/** * @param SchedulerEvent $event */ public function onSchedule(SchedulerEvent $event) { $schedule = $event->getSchedule(); if ($schedule instanceof Schedule) { $this->logger->debug('Process schedule {schedule}', array('schedule' => $schedule)); if ($job = $schedule->getJob()) { $message = new Message($job->getType(), $job->getTicket(), $job->getTicket()); $this->queueEngine->produce($message); return; } $this->logger->error('There is no job associated with this schedule {schedule}', array('schedule' => $schedule)); } }
/** * @param JobInterface $job * @throws \Exception */ protected function publishJob(JobInterface $job) { $message = new Message($job->getType(), $job->getTicket()); try { $this->producer->produce($message); } catch (\Exception $e) { $this->logger->critical(sprintf('Failed to publish message for job %s (Error: %s)', $job->getTicket(), $e->getMessage()), ['job' => $job, 'exception' => $e]); throw $e; } }
public function testOnScheduleWithoutJob() { $event = new SchedulerEvent(new Schedule()); $this->producer->expects($this->never())->method('produce'); $this->subject->onSchedule($event); }
/** * @expectedException \Exception */ public function testAddRethrowsBackendExceptions() { $job = new Job(); $job->setTicket('ticket'); $this->jobManager->expects($this->once())->method('isManagerOf')->with($job)->willReturn(true); $this->registry->expects($this->any())->method('has')->willReturn(true); $this->producer->expects($this->once())->method('produce')->willThrowException(new \Exception()); $this->subject->add($job); }