/**
  * {@inheritdoc}
  */
 public function doStop()
 {
     $time = time();
     if (null === $this->lastCheck || $this->lastCheck + $this->interval <= $time) {
         $this->lastCheck = $time;
         $this->manager->refresh($this->job);
     }
     return $this->job->getStatus() == Status::CANCELLING() || $this->job->getStatus() == Status::CANCELLED();
 }
Exemple #2
0
 /**
  * {@inheritdoc}
  */
 public function cancel($ticket, $force = false)
 {
     $job = $this->findJob($ticket);
     if (Status::isTerminated($job->getStatus())) {
         return false;
     }
     $isProcessing = $job->getStatus() == Status::PROCESSING();
     $status = $force ? Status::CANCELLED() : ($isProcessing ? Status::CANCELLING() : Status::CANCELLED());
     $this->helper->updateJob($job, $status);
     $this->jobManager->save($job);
     if ($force) {
         $this->locker->release($job->getTicket());
     }
     if (!$isProcessing || $force) {
         $this->dispatcher->dispatch(JobEvents::JOB_TERMINATED, new TerminationEvent($job));
         $message = $force ? 'Forced cancellation of job ' : 'Cancelled job ';
         $this->logger->info($message . $job->getTicket());
     } else {
         $this->logger->info('Request cancellation of job ' . $job->getTicket());
     }
     return $job;
 }
 public static function provideCancelStatus()
 {
     return [[Status::CANCELLED()], [Status::CANCELLING()]];
 }
 /**
  * @param Status $status
  * @dataProvider provideUnterminatedStatus
  */
 public function testCancel(Status $status)
 {
     $isProcessing = $status->getValue() == Status::PROCESSING;
     $job = new Job();
     $job->setTicket('ticket');
     $job->setStatus($status);
     $terminationEvent = new TerminationEvent($job);
     $this->jobManager->expects($this->once())->method('findByTicket')->with($job->getTicket())->willReturn($job);
     $this->helper->expects($this->once())->method('updateJob')->with($job, $isProcessing ? Status::CANCELLING() : Status::CANCELLED())->willReturnCallback(function (JobInterface $job, Status $status) {
         $job->setStatus($status);
     });
     $this->jobManager->expects($this->once())->method('save')->with($this->callback(function ($arg) use($job, $isProcessing) {
         return $arg === $job && $arg->getStatus() == ($isProcessing ? Status::CANCELLING() : Status::CANCELLED());
     }));
     $this->dispatcher->expects($isProcessing ? $this->never() : $this->once())->method('dispatch')->with(JobEvents::JOB_TERMINATED, $terminationEvent);
     $this->subject->cancel($job->getTicket());
 }