private function publishBatch() { // the database transaction needs to be committed before the // message is pushed to Rabbit MQ to prevent jobs from being // processed by workers before they have been moved to buffered_jobs $this->database->publishBatch(); $this->worker_queue_factory->publishBatch(); $this->jobs_queued = 0; }
/** * @covers ::__construct * @covers ::push * @covers ::<private> * @covers \Hodor\JobQueue\AbstractQueueFactory * @covers \Hodor\JobQueue\WorkerQueueFactory */ public function testBatchedJobIsPublishedIfAndOnlyIfBatchIsPublished() { $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']); try { $this->consumer->consume(function () use($expected_job) { $this->fail('A message should not be available for consuming until after batch is published.'); }); } catch (Exception $exception) { // the exception is expected. do nothing. } $this->worker_queue_factory->publishBatch(); $this->consumer->consume(function (IncomingMessage $message) use($expected_job) { $received_job = $message->getContent(); $this->assertEquals($expected_job, ['name' => $received_job['name'], 'params' => $received_job['params'], 'meta' => $received_job['meta']]); }); }