Skip to content
Snippets Groups Projects

#3476814: Handle nulled duplicate jobs

Files
5
+ 13
5
@@ -139,7 +139,9 @@ class Queue extends ConfigEntityBase implements QueueInterface {
*/
public function enqueueJob(Job $job, $delay = 0) {
$job = $this->prepareJob($job);
return $this->getBackend()->enqueueJob($job, $delay);
if ($job) {
$this->getBackend()->enqueueJob($job, $delay);
}
}
/**
@@ -148,24 +150,30 @@ class Queue extends ConfigEntityBase implements QueueInterface {
public function enqueueJobs(array $jobs, $delay = 0) {
$prepared_jobs = [];
foreach ($jobs as $job) {
$prepared_jobs[] = $this->prepareJob($job);
if ($prepared_job = $this->prepareJob($job)) {
$prepared_jobs[] = $prepared_job;
}
}
if ($prepared_jobs) {
$this->getBackend()->enqueueJobs($prepared_jobs, $delay);
}
return $this->getBackend()->enqueueJobs($prepared_jobs, $delay);
}
/**
* Prepare a job for enqueueing.
*
* If a null is returned, this is an instruction to discard the job.
*
* @param \Drupal\advancedqueue\Job $job
* The job to prepare.
*
* @return \Drupal\advancedqueue\Job
* @return \Drupal\advancedqueue\Job|null
* A job to enqueue. This may or may not be the $job object supplied.
*
* @throws \Drupal\advancedqueue\Exception\InvalidBackendException
* Throws an exception if the queue's backend cannot handle the given job.
*/
protected function prepareJob(Job $job): Job {
protected function prepareJob(Job $job): ?Job {
$job->setQueueId($this->id());
$job_type_manager = \Drupal::service('plugin.manager.advancedqueue_job_type');
if (!$job_type_manager->getDefinition($job->getType())['allow_duplicates']) {
Loading