By zaporylie on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
8.x-1.x
Introduced in version:
8.x-1.1
Issue links:
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
fingerprintfield has been added to theadvancedqueuedatabase table. This field stores a unique hash that identifies the job, preventing duplicates. - Backend Interface: A new
SupportsDetectingDuplicateJobsInterfacehas been introduced for backends that support detecting duplicate jobs.Databasebacked now implementsSupportsDetectingDuplicateJobsInterface - Job Type Annotation: The
allow_duplicatesconfiguration has been added to job types and it defaults to TRUE to keep backward compatibility. When set toFALSE, 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, andInvalidBackendException, thrown when the backend does not support duplicate detection.
Usage:
- To define a job type that should not allow duplicates, set
allow_duplicatestoFALSEin 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 theJobTypeBase - Backends that support duplicate detection must implement the
SupportsDetectingDuplicateJobsInterfaceand 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