verk
verk copied to clipboard
[question] is it possible to configure a queue to allow to schedule a specific job only once?
i want to allow a job(same class, args and queue) to be schedule only once... is that possible? i found out that there isn't any easi api to get scheduled jobs or to verify running jobs... i kinda use Verk.SortedSet.range/4
for that but idk if that is consistent.... i've seen duplicate jobs scheduling nevertheless
Even if you implement something with Verk.SortedSet
there's always a chance for a race condition:
Suppose that the job just came out of the scheduled set.
- Check if this job does not exist on the schedule set
- Job is not scheduled but is running
- Add new job to the schedule set
In this case your code will add a new job to the scheduled set.
I'm not sure what's the best approach here 🤔
If the goal is simply to prevent rescheduling, one possible solution:
- create a new set
scheduled
- serialize every
Job
struct to a string - before scheduling, attempt to write the serialized
Job
to thescheduled
set using an atomic read/update command, possibly HSETNX - only schedule the
Job
if HSETNX returns1
, otherwise we discard it as a duplicate
The main issue that arises: how we do garbage collect the set? The maximum set size is ~14mil (2^32), so if you are doing normal-ish production volume then you can't persist the set forever. How much of a problem this is depends on the requirements you had in mind @fcevado.