/** * Scans table for specific items we want to update * @return array */ private function getJobsToFetchStatsFor() { $params = ['TableName' => $this->tableName, 'FilterExpression' => <<<EXPR attribute_exists(sapiProjectId) and attribute_not_exists(componentName) and not begins_with(runId, :notBeginsWith) and ( attribute_not_exists(syrupJobId) or (attribute_exists(syrupJobId) and syrupJobId <> :syrupJobIdSyncAction) ) and attribute_not_exists(hasSyrupJob) EXPR , 'Limit' => self::MAX_DOCUMENTS_TO_PROCESS, 'ExpressionAttributeValues' => [':notBeginsWith' => ['S' => 'p'], ':syrupJobIdSyncAction' => ['S' => '0']]]; $ids = []; $marshaler = new Marshaler(); do { if (isset($response) && isset($response['LastEvaluatedKey'])) { $params['ExclusiveStartKey'] = $response['LastEvaluatedKey']; } $response = $this->dynamoDbClient->scan($params); foreach ($response['Items'] as $item) { $ids[] = $marshaler->unmarshalValue($item['runId']); } } while (isset($response['LastEvaluatedKey']) && count($ids) <= 5000); return $ids; }
/** * Get items via the scan call * @param string $table The item table * @param Context\Scan|null $context The call context * @return Collection */ public function scan($table, Context\Scan $context = null) { if (null !== $this->logger) { $this->log('Scan on table ' . $table); } $parameters = array('TableName' => $table); if (null !== $context) { $parameters += $context->getForDynamoDB(); } if (null !== $this->logger) { $this->log('Scan request paramaters : ' . print_r($parameters, true), Logger::DEBUG); } $response = $this->connector->scan($parameters); if (null !== $this->logger) { $this->log('Scan request response : ' . print_r($response, true), Logger::DEBUG); $this->log($response['ScannedCount'] . ' scanned items'); } $this->addConsumedReadUnits($table, floatval($response['ConsumedCapacityUnits'])); if (isset($response['LastEvaluatedKey'])) { if (null === $context) { $nextContext = new Context\Scan(); } else { $nextContext = clone $context; } $nextContext->setExclusiveStartKey($response['LastEvaluatedKey']); if (null !== $this->logger) { $this->log('More Items to retrieve'); } } else { $nextContext = null; } $items = new Collection($nextContext, $response['Count']); if (!empty($response['Items'])) { foreach ($response['Items'] as $responseItem) { $item = new Item($table); $item->populateFromDynamoDB($responseItem); $items->add($item); } } if (null !== $this->logger) { $this->log('Find ' . count($items) . ' Items'); } return $items; }
/** * Executes the Scan operation. * * @param string $tableName The name of the table containing the requested items. * @param array $args Arguments of the query * * @return Guzzle\Service\Resource\Model * * @see http://docs.aws.amazon.com/aws-sdk-php/latest/class-Aws.DynamoDb.DynamoDbClient.html#_scan */ public function scan($tableName, array $args) { $args['TableName'] = $tableName; return $this->client->scan($args); }