protected static function unformatValue($value) { $marshaler = new Marshaler(); return $marshaler->unmarshalValue($value); // represented as arrays, though there is only ever one item present // foreach ($value as $type => $actual) { // switch ($type) { // case Type::S: // case Type::B: // return $actual; // case Type::N: // if (intval($actual) == $actual) { // return intval($actual); // } else { // return floatval($actual); // } // case Type::SS: // case Type::BS: // return $actual; // case Type::NS: // $out = []; // foreach ($actual as $item) { // if (intval($item) == $item) { // $out[] = intval($item); // } else { // $out[] = floatval($item); // } // } // // return $out; // } // } // // return $value; }
/** * 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; }
/** * Batch fetches items from DynamoDb * @param array $runIds * @return array */ private function getDocumentsForRunIdsFromDynamoDb(array $runIds) { /** @var DynamoDbClient $dynamoDbClient */ $dynamoDbClient = $this->container->get('queue.dynamodb_client'); $tableName = $this->container->getParameter('container_stats_dynamodb.table_name'); $params = ['RequestItems' => [$tableName => ['ConsistentRead' => true, 'Keys' => array_map(function ($runId) { return ['runId' => ['S' => $runId]]; }, $runIds)]]]; $marshaler = new Marshaler(); $metrics = []; $response = $dynamoDbClient->batchGetItem($params); if (!empty($response['Responses'][$tableName])) { foreach ($response['Responses'][$tableName] as $metric) { $metrics[$marshaler->unmarshalValue($metric['runId'])] = $marshaler->unmarshalItem($metric); } } return $metrics; }