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; }
/** * @param FactoryInterface $factory * @param string $uniqid * @param array $jobs * @return array */ private function bufferJobs(FactoryInterface $factory, $uniqid, array $jobs) { $buffered_at = date('c', time() - 3600); foreach ($jobs as $job) { $options = []; if (isset($job['run_after'])) { $options['run_after'] = date('c', time() + $job['run_after']); } if (isset($job['job_rank'])) { $options['job_rank'] = $job['job_rank']; } if (isset($job['mutex_id'])) { $options['mutex_id'] = "mutex-{$uniqid}-{$job['mutex_id']}"; } $factory->getBufferWorker()->bufferJob('fast-jobs', ['name' => "job-{$uniqid}-{$job['name']}", 'params' => ['value' => $uniqid], 'options' => $options, 'meta' => ['buffered_at' => $buffered_at, 'buffered_from' => "host-{$uniqid}-{$job['name']}"]]); } }