Пример #1
0
 public function setUp()
 {
     $this->mockQueueManager = $this->getMockBuilder(QueueManager::class)->disableOriginalConstructor()->getMock();
     $this->testQueue = new TestQueue('TestQueue');
     $this->mockQueueManager->expects($this->any())->method('getQueue')->with('TestQueue')->will($this->returnValue($this->testQueue));
     $this->jobManager = new JobManager();
     $this->inject($this->jobManager, 'queueManager', $this->mockQueueManager);
 }
Пример #2
0
 /**
  * @test
  */
 public function queueNamePrefixFromPresetCanBeOverruled()
 {
     $this->inject($this->queueManager, 'settings', ['presets' => ['somePreset' => ['queueNamePrefix' => 'presetPrefix']], 'queues' => ['TestQueue' => ['preset' => 'somePreset', 'queueNamePrefix' => 'overriddenPrefix', 'className' => TestQueue::class]]]);
     /** @var TestQueue $queue */
     $queue = $this->queueManager->getQueue('TestQueue');
     $this->assertSame('overriddenPrefixTestQueue', $queue->getName());
 }
 /**
  * Execute one job
  *
  * @param string $queue
  * @param string $serializedMessage An instance of Message serialized and base64-encoded
  * @return void
  * @internal This command is mainly used by the JobManager and FakeQueue in order to execute commands in sub requests
  */
 public function executeCommand($queue, $serializedMessage)
 {
     /** @var Message $message */
     $message = unserialize(base64_decode($serializedMessage));
     $queue = $this->queueManager->getQueue($queue);
     $this->jobManager->executeJobForMessage($queue, $message);
 }
Пример #4
0
 public function setUp()
 {
     parent::setUp();
     $this->mockQueueManager = $this->getMockBuilder(QueueManager::class)->disableOriginalConstructor()->getMock();
     $this->testQueue = new TestQueue('TestQueue');
     $this->mockQueueManager->expects($this->any())->method('getQueue')->with('TestQueue')->will($this->returnValue($this->testQueue));
     $this->mockQueueManager->expects($this->any())->method('getQueueSettings')->with('TestQueue')->will($this->returnCallback(function () {
         return $this->queueSettings;
     }));
     $this->jobManager = new JobManager();
     $this->inject($this->jobManager, 'queueManager', $this->mockQueueManager);
     self::$bootstrap->getSignalSlotDispatcher()->connect(JobManager::class, 'messageSubmitted', $this, 'logSignal');
     self::$bootstrap->getSignalSlotDispatcher()->connect(JobManager::class, 'messageTimeout', $this, 'logSignal');
     self::$bootstrap->getSignalSlotDispatcher()->connect(JobManager::class, 'messageReserved', $this, 'logSignal');
     self::$bootstrap->getSignalSlotDispatcher()->connect(JobManager::class, 'messageFinished', $this, 'logSignal');
     self::$bootstrap->getSignalSlotDispatcher()->connect(JobManager::class, 'messageReleased', $this, 'logSignal');
     self::$bootstrap->getSignalSlotDispatcher()->connect(JobManager::class, 'messageFailed', $this, 'logSignal');
 }
 /**
  * Submit a message to a given queue
  *
  * This command can be used to "manually" add messages to a given queue.
  *
  * <b>Example:</b>
  * <i>flow queue:submit some-queue "some payload" --options '{"delay": 14}'</i>
  *
  * To make this work with the <i>JobManager</i> the payload has to be a serialized
  * instance of an object implementing <i>JobInterface</i>.
  *
  * @param string $queue Name of the queue to submit a message to (e.g. "some-queue")
  * @param string $payload Arbitrary payload, for example a serialized instance of a class implementing JobInterface
  * @param string $options JSON encoded, for example '{"some-option": "some-value"}'
  * @return void
  */
 public function submitCommand($queue, $payload, $options = null)
 {
     $queue = $this->queueManager->getQueue($queue);
     if ($options !== null) {
         $options = json_decode($options, true);
     }
     $messageId = $queue->submit($payload, $options !== null ? $options : []);
     $this->outputLine('<success>Submitted payload to queue "%s" with ID "%s".</success>', [$queue->getName(), $messageId]);
 }
Пример #6
0
 /**
  *
  * @param string $queueName
  * @param integer $limit
  * @return JobInterface[]
  * @api
  */
 public function peek($queueName, $limit = 1)
 {
     $queue = $this->queueManager->getQueue($queueName);
     $messages = $queue->peek($limit);
     return array_map(function (Message $message) {
         $job = unserialize($message->getPayload());
         return $job;
     }, $messages);
 }