Adding a "don't add if job already exists" flag to the queue service #17533
Unanswered
jamie-s-white
asked this question in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
The problem
I was tempted to write another PR to add a "don't add if job already exists" flag to the queue service, because we've started doing a lot of this grunt work in our plugins, and it feels beneficial to have this in core Craft.
Currently, we have our resaveEntry job, with the following core piece of code:
However, this gets called when we stitch together entries via an entries field, which is a 1 to many relationship. This ends up with us adding multiple resaveEntry jobs to the queue:
Clearly, all the repeat jobs are doing is busting the cache for that entry every time it is resaved, which slows down the site, and takes the queue longer to clear whilst it continually completes the same repeated task with no actual benefit.
I have now done some work with our plugins to query the queue table to see if there is already a resaveEntry job with the same entry and site ID that has not yet been started, and, if it exists, don't add it another time... Before realising what I really wanted was this "don't add if job already exists" flag in core Craft.
However, when looking through the core Craft CMS code, I noticed that you had already done a similar thing with UpdateSearchIndex jobs, but you had made this an UpdateSearchIndex specific function, instead of an extension of the queue service:
93199c1#diff-ec7c4688742463abe8af2bf94ba47e0ebafa5e517046da12b9b4e4cc4ea73381R344
It feels like it would be beneficial to abstract this for the queue service, add a more generic
isJobPending
function which checks to see if a job with exactly the same parameters already exists in the queue, and not add it if that task is already queued?It then feels like this could be utilised further in core Craft to cover jobs such as pruning revisions?
Beta Was this translation helpful? Give feedback.
All reactions