Пример #1
0
 /**
  * @param string $queue_name
  * @param array $job
  */
 public function bufferJob($queue_name, array $job)
 {
     $job_id = $this->database->allocateId();
     $job = array_replace_recursive(['name' => "job-name-{$job_id}", 'options' => ['run_after' => date('c'), 'job_rank' => 5, 'mutex_id' => "hodor-{$job_id}"]], $job);
     $row = ['buffered_job_id' => $job_id, 'queue_name' => $queue_name, 'job_name' => $job['name'], 'job_params' => json_encode($job['params'], JSON_FORCE_OBJECT), 'buffered_at' => $job['meta']['buffered_at'], 'buffered_from' => $job['meta']['buffered_from'], 'inserted_from' => gethostname(), 'run_after' => $job['options']['run_after'], 'job_rank' => $job['options']['job_rank'], 'mutex_id' => $job['options']['mutex_id']];
     $this->database->insert('buffered_jobs', $job_id, $row);
 }
Пример #2
0
 /**
  * @param string $status
  * @param array $meta
  * @throws BufferedJobNotFoundException
  */
 private function markJobAsFinished($status, array $meta)
 {
     if (!$this->database->has('queued_jobs', $meta['buffered_job_id'])) {
         throw new BufferedJobNotFoundException("", $meta['buffered_job_id'], $meta);
     }
     $row = $this->database->delete('queued_jobs', $meta['buffered_job_id']);
     $this->database->insert("{$status}_jobs", $meta['buffered_job_id'], $row);
 }
Пример #3
0
 /**
  * @param int $count
  */
 private function assertJobsAreQueued($count)
 {
     $uniqid = uniqid();
     for ($i = 1; $i <= $count; $i++) {
         $row = ['buffered_job_id' => "{$uniqid}-{$i}-id", 'queue_name' => 'default-worker', 'job_name' => "{$uniqid}-{$i}-name", 'job_params' => ["{$uniqid}-{$i}-params"], 'run_after' => date('c'), 'job_rank' => $i, 'mutex_id' => "{$uniqid}-{$i}-mutex"];
         $this->database->insert('buffered_jobs', "{$uniqid}-{$i}-id", $row);
     }
     $this->superqueue->queueJobsFromDatabaseToWorkerQueue();
     $confirmed_messages = 0;
     for ($i = 1; $i <= $count; $i++) {
         $mq_message = json_decode($this->message_bank->consumeMessage()->getContent(), true);
         if ("{$uniqid}-{$i}-name" === $mq_message['name'] && $this->database->has('queued_jobs', "{$uniqid}-{$i}-id")) {
             ++$confirmed_messages;
         }
     }
     $this->assertSame($count, $confirmed_messages);
 }
Пример #4
0
 public function publishBatch()
 {
     $this->in_batch = false;
     foreach ($this->batched_jobs as $job) {
         $job['queued_job_id'] = uniqid();
         $this->database->delete('buffered_jobs', $job['buffered_job_id']);
         $this->database->insert('queued_jobs', $job['buffered_job_id'], $job);
     }
     $this->batched_jobs = [];
 }
Пример #5
0
 /**
  * @param callable $job_runner
  */
 private function checkMessageForJobIsAcknowledged(callable $job_runner)
 {
     $uniqid = uniqid();
     $expected_job = ['name' => "some-job-{$uniqid}", 'params' => ['value' => $uniqid], 'meta' => ['buffered_job_id' => rand(1, 10)]];
     $this->database->insert('queued_jobs', $expected_job['meta']['buffered_job_id'], []);
     $this->worker_queue->push($expected_job['name'], $expected_job['params'], $expected_job['meta']);
     $this->worker_queue->runNext($job_runner);
     $this->message_bank->emulateReconnect();
     $this->worker_queue->runNext(function () {
     });
 }
Пример #6
0
 /**
  * @covers ::has
  */
 public function testARowCanBeDetectedInATable()
 {
     $this->assertFalse($this->database->has('buffered_jobs', 1));
     $this->database->insert('buffered_jobs', 1, []);
     $this->assertTrue($this->database->has('buffered_jobs', 1));
 }