From de39d4183d41b7a03ec30d25b4f0f510d2a37af5 Mon Sep 17 00:00:00 2001 From: Richard deMeester Date: Fri, 16 Jun 2023 18:51:00 +1000 Subject: [PATCH 1/2] [IMP] queue_job: identity_key enhancements 1. In production, a job which is waiting dependencies or which has started, but not completed, should not be repeated if the identity_key matches. 2. In tests, the mock queue handler is now enhanced to allow better mimicking of the identity_key blocks from production. 3. In tests, the mock queue handler now clears the enqueued jobs after performing them, to better reproduce what a production environment would do. --- queue_job/job.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/queue_job/job.py b/queue_job/job.py index 7fb39f9450..c747531a62 100644 --- a/queue_job/job.py +++ b/queue_job/job.py @@ -300,7 +300,7 @@ def job_record_with_same_identity_key(self): .search( [ ("identity_key", "=", self.identity_key), - ("state", "in", [WAIT_DEPENDENCIES, PENDING, ENQUEUED]), + ("state", "in", [WAIT_DEPENDENCIES, PENDING, ENQUEUED, STARTED]), ], limit=1, ) From 7fcc57572e06c30495ff1ac74c58f33d747c6758 Mon Sep 17 00:00:00 2001 From: Simone Orsi Date: Tue, 21 Nov 2023 17:21:03 +0100 Subject: [PATCH 2/2] queue_job: job_record_with_same_identity_key ignore STARTED Good explanation from Guewen: Depending on the use case, we should or should not include. As part of my current work, I use Sidekiq daily. They have a similar feature, but you can set a per-job parameter unique_until with options: start (that would mean up to ENQUEUED here) or success (that would be up to STARTED here). Think about this use case: a job refreshes a cache. Data have changed, we create a pending job. Data change again, no new job because the job is still pending. Job starts. Data change while the job is running. In this very case, we'd like to enqueue a new job otherwise the cache will be outdated. I reckon that both cases are valid, but I fear adding this state in the domain may, silently and in subtle ways, existing behaviors. --- queue_job/job.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/queue_job/job.py b/queue_job/job.py index c747531a62..7fb39f9450 100644 --- a/queue_job/job.py +++ b/queue_job/job.py @@ -300,7 +300,7 @@ def job_record_with_same_identity_key(self): .search( [ ("identity_key", "=", self.identity_key), - ("state", "in", [WAIT_DEPENDENCIES, PENDING, ENQUEUED, STARTED]), + ("state", "in", [WAIT_DEPENDENCIES, PENDING, ENQUEUED]), ], limit=1, )