/**
  * Sets status of the job to cancelled if process controller indicates to exit.
  *
  * @return boolean
  */
 public function doStop()
 {
     if ($this->controller->doStop()) {
         $this->job->setStatus(Status::CANCELLED());
         return true;
     }
     return false;
 }
 public function testConsumeChecksController()
 {
     $queue = $this->createMock(Queue::class);
     $this->controller->expects($this->once())->method('doStop')->willReturn(true);
     $subject = $this->buildSubject(['invoke']);
     $subject->consume($queue);
     $subject->expects($this->never())->method('invoke');
 }
 /**
  * @param bool $doStop
  * @param bool $valid
  * @dataProvider getBooleanArray
  */
 public function testValid($doStop, $valid)
 {
     $this->scheduleIterator->expects($this->any())->method('valid')->willReturn($valid);
     $this->controller->expects($this->any())->method('doStop')->willReturn($doStop);
     if ($doStop) {
         $this->assertEquals(false, $this->subject->valid());
     } else {
         $this->assertEquals($valid, $this->subject->valid());
     }
 }
Beispiel #4
0
 /**
  * @ParamType("seconds", type="integer")
  * @ParamType("logger", type="@abc.logger")
  * @param                 $seconds
  * @param LoggerInterface $logger
  */
 public function sleep($seconds, LoggerInterface $logger)
 {
     $logger->info('start sleeping for {seconds}', ['seconds' => $seconds]);
     $start = time();
     do {
         sleep(1);
         $seconds--;
     } while ($seconds > 0 && !$this->controller->doStop());
     $logger->info('stopped sleeping after {seconds}', ['seconds' => time() - $start]);
 }
 public function testConsumeChecksController()
 {
     $queue = 'foobar';
     $message = $this->createMock(MessageInterface::class);
     $iterator = new TestIterator([$message, $message]);
     $this->backendProvider->expects($this->once())->method('getBackend')->with($queue)->willReturn($this->backend);
     $this->backend->expects($this->any())->method('getIterator')->willReturn($iterator);
     $this->controller->expects($this->any())->method('doStop')->willReturn(true);
     $this->backend->expects($this->never())->method('handle');
     $this->subject->consume($queue);
 }
 /**
  * {@inheritdoc}
  */
 public function tick(Queue $queue, array $options = [])
 {
     // weired, no clue why this is necessary, but somehow configure is not invoked otherwise
     $this->doConfigure($options);
     if ($this->controller->doStop()) {
         return false;
     }
     if ($this->controller->doPause()) {
         return true;
     }
     return parent::tick($queue, $options);
 }
Beispiel #7
0
 /**
  * @ReturnType("string")
  * @return string|null
  */
 public function cancel()
 {
     while (!$this->controller->doStop()) {
         return 'running';
     }
     return 'cancelled';
 }
 /**
  * {@inheritdoc}
  */
 public function doPause()
 {
     if ($this->fallbackController != null) {
         return $this->fallbackController->doPause();
     }
     pcntl_signal_dispatch();
     return $this->pause;
 }
 protected function tick(BackendInterface $backend, array $options = [])
 {
     $this->configure($options);
     $iterator = $backend->getIterator();
     foreach ($iterator as $message) {
         if ($this->controller->doPause()) {
             return true;
         }
         if ($this->controller->doStop()) {
             return false;
         }
         if (microtime(true) > $this->options['max-runtime']) {
             return false;
         }
         $backend->handle($message, $this->notificationDispatcher);
         $this->eventDispatcher->dispatch(IterateEvent::EVENT_NAME, new IterateEvent($iterator, $backend, $message));
         if (null !== $this->options['max-messages'] && !(bool) --$this->options['max-messages']) {
             return false;
         }
     }
     return !$this->options['stop-when-empty'];
 }
 /**
  * {@inheritdoc}
  */
 public function valid()
 {
     return !$this->controller->doStop() && $this->scheduleIterator->valid();
 }
 public function testDoExitControllerReturnsTrue()
 {
     $this->controller->expects($this->any())->method('doStop')->willReturn(true);
     $this->assertTrue($this->subject->doStop());
     $this->assertEquals(Status::CANCELLED(), $this->job->getStatus());
 }
 /**
  * {@inheritdoc}
  */
 public function valid()
 {
     return !$this->controller->doExit() && $this->messageIterator->valid();
 }