Change record status: 
Project: 
Introduced in branch: 
8.x-1.x
Introduced in version: 
8.x-1.1
Description: 

The AdvancedQueue module has been updated to support defining jobs as unique. This enhancement introduces the ability to prevent duplicate jobs from being enqueued, ensuring that jobs with the same unique fingerprint are not duplicated in the queue.

Changes:

  • Fingerprint Field: A new fingerprint field has been added to the advancedqueue database table. This field stores a unique hash that identifies the job, preventing duplicates.
  • Backend Interface: A new SupportsDetectingDuplicateJobsInterface has been introduced for backends that support detecting duplicate jobs. Database backed now implements SupportsDetectingDuplicateJobsInterface
  • Job Type Annotation: The allow_duplicates configuration has been added to job types and it defaults to TRUE to keep backward compatibility. When set to FALSE, the system checks for duplicates before enqueuing jobs.
  • Exceptions: Two new exceptions have been introduced: DuplicateJobException, thrown when a job is detected as a duplicate, and InvalidBackendException, thrown when the backend does not support duplicate detection.

Usage:

  • To define a job type that should not allow duplicates, set allow_duplicates to FALSE in the job type's annotation.
  • The job type plugin must implement the createJobFingerprint() method to generate a unique fingerprint for each job based on its payload, type, and queue. Default implementation was added to the JobTypeBase
  • Backends that support duplicate detection must implement the SupportsDetectingDuplicateJobsInterface and provide a method for identifying and handling duplicate jobs.

Before:

/**
 * Example job type.
 *
 * @AdvancedQueueJobType(
 *   id = "example_job_type",
 *   label = @Translation("Job type"),
 * )
 */
class Job extends JobTypeBase {

  /**
   * {@inheritdoc}
   */
  public function process(Job $job) {
    return JobResult::success();
  }

}

After:


/**
 * Example job type.
 *
 * @AdvancedQueueJobType(
 *   id = "example_job_type",
 *   label = @Translation("Job type"),
 *   allow_duplicates = false,
 * )
 */
class Job extends JobTypeBase {

  /**
   * {@inheritdoc}
   */
  public function process(Job $job) {
    return JobResult::success();
  }

}
Impacts: 
Module developers