Ejemplo n.º 1
0
 public function processBuffer()
 {
     $this->consumer_q->consume(function (IncomingMessage $message) {
         $content = $message->getContent();
         $queue_name = $this->config->getJobQueueConfig()->getWorkerQueueName($content['name'], $content['params'], $content['options']);
         $this->database->bufferJob($queue_name, ['name' => $content['name'], 'params' => $content['params'], 'options' => $content['options'], 'meta' => $content['meta']]);
         $message->acknowledge();
     });
 }
Ejemplo n.º 2
0
 /**
  * @covers ::__construct
  * @covers ::consume
  */
 public function testConsumerReceivesExpectedCallback()
 {
     $expected_callback = function () {
     };
     $consumer = function (callable $callback) use($expected_callback) {
         $this->assertSame($expected_callback, $callback);
     };
     $consumer_queue = new ConsumerQueue($consumer);
     $consumer_queue->consume($expected_callback);
 }
Ejemplo n.º 3
0
 /**
  * @covers ::__construct
  * @covers ::push
  * @covers ::<private>
  * @covers \Hodor\JobQueue\AbstractQueueFactory
  * @covers \Hodor\JobQueue\WorkerQueueFactory
  * @expectedException Exception
  */
 public function testBatchedJobIsDiscardedIfBatchIsDiscarded()
 {
     $uniqid = uniqid();
     $expected_job = ['name' => "some-job-{$uniqid}", 'params' => ['value' => $uniqid], 'meta' => ['buffered_job_id' => rand(1, 10)]];
     $this->worker_queue_factory->beginBatch();
     $this->worker_queue->push($expected_job['name'], $expected_job['params'], $expected_job['meta']);
     $this->worker_queue_factory->discardBatch();
     $this->consumer->consume(function () {
     });
 }
Ejemplo n.º 4
0
 /**
  * @param  callable $job_runner
  */
 public function runNext(callable $job_runner)
 {
     $this->consumer_q->consume(function (IncomingMessage $message) use($job_runner) {
         $start_time = new DateTime();
         $mark_job_as_failed_if_not_successful = $this->getFailureCallback();
         register_shutdown_function($mark_job_as_failed_if_not_successful, $message, $start_time);
         $content = $message->getContent();
         $name = $content['name'];
         $params = $content['params'];
         $meta = $content['meta'];
         $title = implode(" ", $_SERVER['argv']) . " ({$meta['buffered_job_id']}:{$name})";
         cli_set_process_title($title);
         try {
             call_user_func($job_runner, $name, $params);
             $this->markJobAsSuccessful($message, $start_time);
         } finally {
             $mark_job_as_failed_if_not_successful($message, $start_time);
         }
     });
 }