public function handle(array $record) { $this->initStorageApiClient(); if (!$this->storageApiClient || $record['level'] == Logger::DEBUG) { return false; } $event = new Event(); if (!empty($record['component'])) { $event->setComponent($record['component']); } else { $event->setComponent($this->appName); } $event->setMessage(\Keboola\Utils\sanitizeUtf8($record['message'])); $event->setRunId($this->storageApiClient->getRunId()); $params = []; if (isset($record['http'])) { $params['http'] = $record['http']; } $event->setParams($params); $results = []; if (isset($record['context']['exceptionId'])) { $results['exceptionId'] = $record['context']['exceptionId']; } if (isset($record['context']['job'])) { $results['job'] = $record['context']['job']; } $event->setResults($results); switch ($record['level']) { case Logger::ERROR: $type = Event::TYPE_ERROR; break; case Logger::CRITICAL: case Logger::EMERGENCY: case Logger::ALERT: $type = Event::TYPE_ERROR; $event->setMessage("Application error"); $event->setDescription("Contact support@keboola.com"); break; case Logger::WARNING: case Logger::NOTICE: $type = Event::TYPE_WARN; break; case Logger::INFO: default: $type = Event::TYPE_INFO; break; } $event->setType($type); $this->storageApiClient->createEvent($event); return false; }
protected function sendEventToSapi($type, $message, $componentName) { $sapiEvent = new SapiEvent(); $sapiEvent->setComponent($componentName); $sapiEvent->setMessage($message); $sapiEvent->setRunId($this->storageApi->getRunId()); $sapiEvent->setType($type); $this->storageApi->createEvent($sapiEvent); }
public function killAction($jobId) { /** @var Search $elasticsearch */ $elasticsearch = $this->container->get('syrup.elasticsearch.search'); $job = $elasticsearch->getJob($jobId); if ($job == null) { throw new SyrupComponentException(404, sprintf("Job '%s' not found", $jobId)); } $sapiData = $this->container->get('syrup.storage_api')->getTokenData(); $projectId = $sapiData['owner']['id']; if ($job->getProject()['id'] != $projectId) { throw new SyrupComponentException(404, sprintf("Job id '%s' not found in project", $jobId)); } $sapiEvent = new Event(); $sapiEvent->setComponent($job->getComponent()); $sapiEvent->setMessage('Requested job termination'); $sapiEvent->setRunId($this->storageApi->getRunId()); $sapiEvent->setType(Event::TYPE_INFO); $sapiEvent->setRunId($job->getRunId()); $sapiEvent->setParams(['jobId' => $jobId]); $this->storageApi->createEvent($sapiEvent); $snsConfig = $this->container->getParameter('sns'); $snsClient = new SnsClient(['credentials' => ['key' => $snsConfig['key'], 'secret' => $snsConfig['secret']], 'region' => isset($snsConfig['region']) ? $snsConfig['region'] : 'us-east-1', 'version' => '2010-03-31']); $snsClient->publish(['TopicArn' => $snsConfig['topic_arn'], 'Message' => json_encode(['jobId' => $jobId])]); $jobData = $job->getData(); if (array_key_exists('terminatedBy', $jobData)) { $job->setTerminatedBy(['id' => $sapiData['id'], 'description' => $sapiData['description']]); } $jobMapper = $this->getComponentJobMapper($job->getComponent()); $jobMapper->update($job); return $this->createJsonResponse(["message" => "job termination request accepted for processing"], 202); }