예제 #1
0
 /**
  * Put a job in the queue.
  *
  * @param string       $queueName   Queue name
  * @param JobInterface $job         The job
  * @param \DateTime     $availableAt Time when the job is available for executing
  */
 public function queue($queueName, JobInterface $job, \DateTime $availableAt = null)
 {
     $queue = $this->queueManager->getQueue($queueName);
     $payload = serialize($job);
     $message = new Message($payload);
     $message->setAvailableAt($availableAt);
     $queue->publish($message);
 }
 /**
  * @test
  */
 public function publishMessageWithDelayAndWaitAndReserveUsingTimeoutAndFinishMessage()
 {
     // Make sure the queue is empty.
     $this->assertSame(null, $this->queue->waitAndReserve(), 'Queue should be empty!');
     // Publish new message.
     $newMessage = new Message('TYPO3');
     $newMessage->setAvailableAt(new \DateTime('now + 2sec'));
     $this->assertSame(2, $newMessage->getDelay(), 'Delay does not  match!');
     $this->queue->publish($newMessage);
     // Do the tests.
     $this->assertSame(null, $this->queue->waitAndReserve(), 'There should be no job available at this moment!');
     $message = $this->queue->waitAndReserve(3);
     $this->assertInstanceOf(Message::class, $message);
     $this->assertSame(Message::STATE_RESERVED, $message->getState(), 'Message has not the state reserved!');
     $this->assertNotEmpty($message->getIdentifier(), 'Message identifier should be set!');
     $this->assertTrue($this->queue->finish($message), 'Message could not be finished!');
     $this->assertSame(Message::STATE_DONE, $message->getState(), 'Message has not the state done!');
 }
예제 #3
0
 /**
  * @test
  */
 public function setAvailableAtAndGetDelay()
 {
     $dateTimeFixture = new \DateTime('now + 7sec');
     $this->subject->setAvailableAt($dateTimeFixture);
     $this->assertSame(7, $this->subject->getDelay());
 }