/**
  * Add context in version manager
  *
  * @param JobExecutionEvent $event
  */
 public function addContext(JobExecutionEvent $event)
 {
     $jobInstance = $event->getJobExecution()->getJobInstance();
     if ($jobInstance->getType() === JobInstance::TYPE_IMPORT) {
         $this->versionContext->addContextInfo(sprintf('%s "%s"', JobInstance::TYPE_IMPORT, $jobInstance->getCode()));
     }
 }
 /**
  * Use the notifiers to notify
  *
  * @param JobExecutionEvent $jobExecutionEvent
  */
 public function afterJobExecution(JobExecutionEvent $jobExecutionEvent)
 {
     $jobExecution = $jobExecutionEvent->getJobExecution();
     foreach ($this->notifiers as $notifier) {
         $notifier->notify($jobExecution);
     }
 }
 function it_logs_before_job_execution($logger, JobExecutionEvent $event, JobExecution $jobExecution)
 {
     $event->getJobExecution()->willReturn($jobExecution);
     $jobExecution->__toString()->willReturn('job exec');
     $logger->debug('Job execution starting: job exec')->shouldBeCalled();
     $this->beforeJobExecution($event);
 }
 function it_sets_job_execution_log_file($handler, JobExecutionEvent $event, JobExecution $execution)
 {
     $handler->getFilename()->willReturn('myfilename');
     $event->getJobExecution()->willReturn($execution);
     $execution->setLogFile('myfilename')->shouldBeCalled();
     $this->setJobExecutionLogFile($event);
 }
 function it_register_an_event_and_verify_if_job_is_supported(JobExecutionEvent $event, JobExecution $jobExecution, ArchiverInterface $archiver)
 {
     $archiver->getName()->willReturn('output');
     $this->registerArchiver($archiver);
     $event->getJobExecution()->willReturn($jobExecution);
     $archiver->supports($jobExecution)->willReturn(true)->shouldBeCalled();
     $archiver->archive($jobExecution)->shouldBeCalled();
     $this->beforeStatusUpgrade($event);
 }
 function it_notifies_notifier(Notifier $notifier1, Notifier $notifier2, JobExecutionEvent $event, JobExecution $execution)
 {
     $this->registerNotifier($notifier1);
     $this->registerNotifier($notifier2);
     $event->getJobExecution()->willReturn($execution);
     $notifier1->notify($execution)->shouldBeCalled();
     $notifier2->notify($execution)->shouldBeCalled();
     $this->afterJobExecution($event);
 }
 /**
  * Delegate archiving to the registered archivers
  *
  * @param JobExecutionEvent $event
  */
 public function beforeStatusUpgrade(JobExecutionEvent $event)
 {
     $jobExecution = $event->getJobExecution();
     foreach ($this->archivers as $archiver) {
         if ($archiver->supports($jobExecution)) {
             $archiver->archive($jobExecution);
         }
     }
 }
 /**
  * Notify a user of the end of the job
  *
  * @param JobExecutionEvent $event
  */
 public function afterJobExecution(JobExecutionEvent $event)
 {
     $jobExecution = $event->getJobExecution();
     $user = $jobExecution->getUser();
     if (null === $user) {
         return;
     }
     $notification = $this->createNotification($jobExecution);
     $this->notifier->notify($notification, [$user]);
 }
 function let(NotificationManager $manager, JobExecutionEvent $event, JobExecution $jobExecution, StepExecution $stepExecution, ArrayCollection $warnings, JobInstance $jobInstance, UserInterface $user, BatchStatus $status)
 {
     $this->beConstructedWith($manager);
     $jobExecution->getUser()->willReturn($user);
     $jobExecution->getStepExecutions()->willReturn([$stepExecution]);
     $jobExecution->getStatus()->willReturn($status);
     $jobExecution->getJobInstance()->willReturn($jobInstance);
     $stepExecution->getWarnings()->willReturn($warnings);
     $jobExecution->getId()->willReturn(5);
     $jobInstance->getType()->willReturn('export');
     $jobInstance->getLabel()->willReturn('Product export');
     $event->getJobExecution()->willReturn($jobExecution);
 }
 /**
  * Notify a user of the end of the job
  *
  * @param JobExecutionEvent $event
  */
 public function afterJobExecution(JobExecutionEvent $event)
 {
     $jobExecution = $event->getJobExecution();
     $user = $jobExecution->getUser();
     if (null === $user) {
         return;
     }
     if ($jobExecution->getStatus()->isUnsuccessful()) {
         $status = 'error';
     } else {
         $status = 'success';
         foreach ($jobExecution->getStepExecutions() as $stepExecution) {
             if ($stepExecution->getWarnings()->count()) {
                 $status = 'warning';
                 break;
             }
         }
     }
     $jobInstance = $jobExecution->getJobInstance();
     $type = $jobInstance->getType();
     // TODO: maybe create a registry or something similar to load routes ?
     $this->generateNotification($jobExecution, $user, $type, $status);
 }
 /**
  * Set the job execution log file
  *
  * @param JobExecutionEvent $event
  */
 public function setJobExecutionLogFile(JobExecutionEvent $event)
 {
     $jobExecution = $event->getJobExecution();
     $jobExecution->setLogFile($this->logger->getFilename());
 }
 /**
  * Log the job execution before its status is upgraded
  *
  * @param JobExecutionEvent $event
  */
 public function beforeJobStatusUpgrade(JobExecutionEvent $event)
 {
     $jobExecution = $event->getJobExecution();
     $this->logger->debug(sprintf('Upgrading JobExecution status: %s', $jobExecution));
 }
 function let(VersionContext $versionContext, JobExecutionEvent $event, JobExecution $jobExecution, JobInstance $jobInstance)
 {
     $this->beConstructedWith($versionContext);
     $event->getJobExecution()->willReturn($jobExecution);
     $jobExecution->getJobInstance()->willReturn($jobInstance);
 }