/** * @param TaskResult $taskResult * @return TaskResult * @throws \Exception */ protected final function fillComponentData(TaskResult $taskResult) { if ($taskResult->getComponent()) { $url = $this->componentsList->getComponentUri($taskResult->getComponent()); if (!$url) { throw new \Exception(sprintf('Component "%s" not found', $taskResult->getComponent())); } // build url if ($taskResult->getAction()) { $url .= substr($url, -1) == '/' ? '' : '/'; $url .= $taskResult->getAction(); } $taskResult->getTask()->setComponentUrl($url); } return $taskResult; }
/** * @param Elasticsearch\Job $job * @param Orchestration $orchestration * @param Elasticsearch\JobManager $jobManager * @param KbcComponentsList $components */ public function sendJobWarningMessage(Elasticsearch\Job $job, Orchestration $orchestration, Elasticsearch\JobManager $jobManager, KbcComponentsList $components) { /** * @var Notification[] $notifications */ $notifications = array_filter($orchestration->getNotifications(), function ($row) { /** * @var Notification $row */ if (!\Swift_Validate::email($row->getEmail())) { return false; } return $row->getChannel() === Job::STATUS_WARNING; }); $notificationsEmails = $jobManager->getWarningNotificationsEmails($job); if (!$notificationsEmails) { $notificationsEmails = array(); } // validating emails foreach ($notificationsEmails as $key => $notificationsEmail) { if (!\Swift_Validate::email($notificationsEmail)) { unset($notificationsEmails[$key]); } } if (!count($notifications) && !count($notificationsEmails)) { return; } $message = \Swift_Message::newInstance(); $message->setSubject(sprintf("[KBC] %s orchestrator %s warning", $job->getTokenOwnerName(), $job->getOrchestrationName())); $message->setFrom(self::MAIL_SENDER); foreach ($notificationsEmails as $notificationsEmail) { $message->addTo($notificationsEmail); } foreach ($notifications as $notification) { if ($job->getInitializedBy() !== 'manually') { if (!in_array($notification->getEmail(), $notificationsEmails)) { $message->addTo($notification->getEmail()); } } } $schedule = null; try { $cronSchedule = CronSchedule::fromCronString($orchestration->getCrontabRecord(), 'en'); $schedule = $cronSchedule->asNaturalLanguage(); } catch (\Exception $e) { } $tasks = $job->getResults(); if (empty($tasks->tasks)) { $tasks = array(); } else { $tasks = $tasks->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:jobWarning.email.html.twig', array('schedule' => $schedule, 'tasks' => $tasks, 'componentsIcons' => $components->getComponentsIcons(), 'componentsNames' => $components->getComponentsNames(), 'componentsTypes' => $this->filterComponentsTypes($components->getComponentsTypes()), 'job' => $job, 'jobUrl' => $jobUrl)), 'text/html'); $this->mailer->send($message); /** * @var \Swift_Spool $spool */ $spool = $this->mailer->getTransport()->getSpool(); $spool->flushQueue($this->mailerTransport); }
public function testComponentsList() { $componentsList = new KbcComponentsList($this->storageApi); $this->assertNotEquals('#', $componentsList->getJobUriTemplate(KeboolaOrchestratorBundle::SYRUP_COMPONENT_NAME)); }