Example #1
0
 /**
  * @param StorageApiEvent $event
  * @return mixed|string Event ID
  */
 private function save(StorageApiEvent $event)
 {
     $event->setParams(array_merge($event->getParams(), array('jobId' => $this->job->getId(), 'orchestrationId' => $this->job->getOrchestrationId(), 'pid' => getmypid())));
     if ($event->getType() == StorageApiEvent::TYPE_ERROR) {
         $event->setParams(array_merge($event->getParams(), array('notificationEmails' => $this->job->getNotificationsEmails())));
     }
     return EventLogger::create($event, $this->client);
 }
 /**
  * @param Elasticsearch\Job $job
  * @param Notification $notification
  * @param Client $sapi
  * @return array
  */
 public static function longProcessingEvents(Elasticsearch\Job $job, Notification $notification, Client $sapi)
 {
     $query = array(sprintf("type:%s", Event::TYPE_WARN), sprintf("message:'%s'", sprintf(CronWatchdogCommand::EVENT_MESSAGE_LONG_PROCESSING, $job->getId())));
     $params = array('q' => implode(' ', $query), 'component' => KeboolaOrchestratorBundle::SYRUP_COMPONENT_NAME, 'limit' => 1000);
     return array_filter($sapi->listEvents($params), function ($row) use($notification) {
         if (empty($row['params'])) {
             return false;
         }
         if (empty($row['params']['notificationEmail'])) {
             return false;
         }
         return $row['params']['notificationEmail'] === $notification->getEmail();
     });
 }
Example #3
0
 /**
  * Update last executed job in orchestration
  *
  * If job failed, send error notification
  *
  * @param SyrupJob $job
  */
 public final function postExecute(SyrupJob $job)
 {
     $this->validateJob($job);
     // not executed or different job - do nothing
     if (!$this->job || !$this->orchestration) {
         return;
     }
     if ($this->job->getId() !== $job->getId()) {
         return;
     }
     $this->job = new Job();
     $this->job->build($job);
     $this->orchestrationManager->updateLastExecutedJob($this->orchestration, $this->job);
     if ($job->getStatus() === SyrupJob::STATUS_ERROR) {
         $this->mailer->sendJobErrorMessage($this->job, $this->orchestration, $this->jobEsManager, $this->componentsList);
     }
     if ($job->getStatus() === SyrupJob::STATUS_WARNING) {
         $this->mailer->sendJobWarningMessage($this->job, $this->orchestration, $this->jobEsManager, $this->componentsList);
     }
 }
Example #4
0
 /**
  * @param Elasticsearch\Job $job
  * @param Orchestration $orchestration
  * @param Notification $notification
  * @param KbcComponentsList $components
  * @param null $averageDuration
  */
 public function sendLongProcessingMessage(Elasticsearch\Job $job, Orchestration $orchestration, Notification $notification, KbcComponentsList $components, $averageDuration = null)
 {
     $notificationsEmails = array($notification->getEmail());
     // validating emails
     foreach ($notificationsEmails as $key => $notificationsEmail) {
         if (!\Swift_Validate::email($notificationsEmail)) {
             unset($notificationsEmails[$key]);
         }
     }
     if (!count($notificationsEmails)) {
         return;
     }
     $message = \Swift_Message::newInstance();
     $message->setSubject(sprintf("[KBC] %s orchestrator %s is still processing", $job->getTokenOwnerName(), $job->getOrchestrationName()));
     $message->setFrom(self::MAIL_SENDER);
     foreach ($notificationsEmails as $notificationsEmail) {
         $message->addTo($notificationsEmail);
     }
     $schedule = null;
     try {
         $cronSchedule = CronSchedule::fromCronString($orchestration->getCrontabRecord(), 'en');
         $schedule = $cronSchedule->asNaturalLanguage();
     } catch (\Exception $e) {
     }
     $results = $job->getResults();
     $tasks = array();
     if (!empty($results->tasks)) {
         $tasks = $results->tasks;
     }
     $jobUrl = $components->getJobUriTemplate(KeboolaOrchestratorBundle::SYRUP_COMPONENT_NAME);
     $jobUrl = str_replace('&&projectId&&', $job->getProjectId(), $jobUrl);
     $jobUrl = str_replace('&&orchestrationId&&', $job->getOrchestrationId(), $jobUrl);
     $jobUrl = str_replace('&&jobId&&', $job->getId(), $jobUrl);
     $message->setBody($this->templating->render('KeboolaOrchestratorBundle:Email:jobLongProcessing.email.html.twig', array('schedule' => $schedule, 'tasks' => $tasks, 'componentsIcons' => $components->getComponentsIcons(), 'componentsNames' => $components->getComponentsNames(), 'componentsTypes' => $this->filterComponentsTypes($components->getComponentsTypes()), 'job' => $job, 'avgDurationString' => Utils::convertDurationToString($averageDuration), 'durationString' => Utils::convertDurationToString(Utils::dateDiffInMinutes($job->getCreatedTime(), new \DateTime()) * 60), 'durationMinutes' => Utils::dateDiffInMinutes($job->getCreatedTime(), new \DateTime()), 'jobUrl' => $jobUrl)), 'text/html');
     $this->mailer->send($message);
     /**
      * @var \Swift_Spool $spool
      */
     $spool = $this->mailer->getTransport()->getSpool();
     $spool->flushQueue($this->mailerTransport);
 }
Example #5
0
 public function postCleanup(Metadata\Job $job)
 {
     $esJob = new Job();
     $esJob->build($job);
     try {
         $token = new Token($this->storageApi);
     } catch (StorageApiException $e) {
         $this->logger->error('Cleanup error - invalid token', array('jobId' => $esJob->getId()));
         throw new UserException(sprintf("Invalid token for job %d", $esJob->getId()), $e);
     }
     $orchestration = $this->orchestrationManager->findOrchestrationById($esJob->getOrchestrationId(), $token);
     if (!$orchestration) {
         $this->logger->error('PostCleanup error - orchestration not found', array('jobId' => $esJob->getId()));
         throw new UserException(sprintf("Orchestration %s not found. Could not update last job", $esJob->getOrchestrationId()));
     }
     $this->logger->debug('PostCleanup job', array('jobId' => $esJob->getId()));
     $this->orchestrationManager->updateLastExecutedJob($orchestration, $esJob);
 }
 /**
  * @param Elasticsearch\Job $job
  * @param Client $sapi
  * @param StorageApi\Notification $notification
  * @param null $averageDuration
  * @throws Exception
  */
 private function logLongProcessing(Elasticsearch\Job $job, Client $sapi, StorageApi\Notification $notification, $averageDuration = null)
 {
     $event = new Event();
     $event->setComponent(KeboolaOrchestratorBundle::SYRUP_COMPONENT_NAME)->setType(Event::TYPE_WARN)->setMessage(sprintf(self::EVENT_MESSAGE_LONG_PROCESSING, $job->getId()))->setParams(array('jobId' => $job->getId(), 'orchestrationId' => $job->getOrchestrationId(), 'createdTime' => $job->getCreatedTime()->format('c'), 'notificationEmail' => $notification->getEmail(), 'tolerance' => $notification->getParameter('tolerance'), 'averageDuration' => $averageDuration));
     StorageApi\EventLogger::create($event, $sapi);
     $this->logger->error(sprintf(self::EVENT_MESSAGE_LONG_PROCESSING, $job->getId()), array('job' => $job->getId(), 'orchestrationId' => $job->getOrchestrationId(), 'projectId' => $job->getProjectId(), 'project' => $job->getTokenOwnerName(), 'averageDuration' => $averageDuration));
 }
 public function updateResult(Job $job, array $result)
 {
     // token decryption/encryption not required
     $syrupJob = $this->syrupJobMapper->get($job->getId());
     $job->setResults($result);
     $syrupJob->setResult($job->getResults());
     $this->syrupJobMapper->update($syrupJob);
     return true;
 }