protected function execute(InputInterface $input, OutputInterface $output) { $this->logger = $this->getContainer()->get('logger'); $this->queue = $this->getContainer()->get('syrup.queue_factory')->get('kill'); $this->elasticsearch = $this->getContainer()->get('syrup.elasticsearch.search'); $this->jobMapper = $this->getContainer()->get('syrup.elasticsearch.current_component_job_mapper'); $this->output = $output; $startTime = time(); // start receiveing messages from SQS do { foreach ($this->queue->receive() as $message) { $this->processMessage($message); } } while (time() - $startTime < static::MAX_RUN_TIME); }
protected function execute(InputInterface $input, OutputInterface $output) { $this->logger = $this->getContainer()->get('logger'); $this->dynamoDbClient = $this->getContainer()->get('queue.dynamodb_client'); $this->tableName = $this->getContainer()->getParameter('container_stats_dynamodb.table_name'); try { $this->dynamoDbClient->describeTable(['TableName' => $this->tableName]); } catch (DynamoDbException $e) { if (strpos($e->getMessage(), 'ResourceNotFoundException') !== false) { throw new \Exception('Table ' . $this->tableName . ' doesn\'t exist.'); } else { throw $e; } } $queueId = $input->getArgument('queueId'); $this->queue = $this->getContainer()->get('syrup.queue_factory')->get($queueId); $startTime = time(); do { foreach ($this->queue->receive(self::MAX_NUMBER_OF_MESSAGES) as $message) { $this->processMessage($message); $this->queue->deleteMessage($message); } } while (time() - $startTime < self::MAX_RUN_TIME); }
/** * Check job in syrup queue * * @param $orchestrationId */ private function sqsScheduledJobTest($orchestrationId) { $assertCount = 1; $requiredStatus = StatusConverter::syrupToOrchestrator(Metadata\Job::STATUS_WAITING); $url = sprintf('/orchestrator/orchestrations/%d/jobs', $orchestrationId); $response = $this->callApiGet($url); $errorMessage = sprintf("Response for call '%s %s' should return only %d jobs.", 'GET', $url, $assertCount); $this->assertCount($assertCount, $response, $errorMessage); $errorMessage = sprintf("Response for call '%s %s' should return list of scheduled jobs.", 'GET', $url); $this->assertArrayHasKey('id', $response[0], $errorMessage); $this->assertArrayHasKey('initializedBy', $response[0], $errorMessage); $this->assertArrayHasKey('status', $response[0], $errorMessage); $this->assertEquals('scheduler', $response[0]['initializedBy'], $errorMessage); $this->assertEquals($requiredStatus, $response[0]['status'], $errorMessage); $this->assertArrayHasKey('isFinished', $response[0]); $this->assertEquals(false, $response[0]['isFinished']); $jobId = $response[0]['id']; $maxTime = 60; $startTime = time(); $errorMessage = sprintf("SQS Message for job '%s' not found.", $jobId); do { foreach ($this->queue->receive() as $message) { /** @var Queue\QueueMessage $message */ $body = $message->getBody(); $errorMessage = 'SQS Message should contains jobId and component name'; $this->assertObjectHasAttribute('jobId', $body, $errorMessage); $this->assertObjectHasAttribute('component', $body, $errorMessage); $errorMessage = 'SQS Message is not from orchestrator'; $this->assertEquals(KeboolaOrchestratorBundle::SYRUP_COMPONENT_NAME, $body->component, $errorMessage); $this->queue->deleteMessage($message); if ($body->jobId == $jobId) { $jobId = null; } } } while ($jobId && time() - $startTime < $maxTime); $this->assertEmpty($jobId, $errorMessage); }