Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[question] is it possible to configure a queue to allow to schedule a specific job only once? #146

Open
fcevado opened this issue Jan 13, 2018 · 2 comments
Labels

Comments

@fcevado
Copy link

fcevado commented Jan 13, 2018

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

@edgurgel
Copy link
Owner

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 🤔

@keyan
Copy link
Contributor

keyan commented Feb 8, 2018

If the goal is simply to prevent rescheduling, one possible solution:

  1. create a new set scheduled
  2. serialize every Job struct to a string
  3. before scheduling, attempt to write the serialized Job to the scheduled set using an atomic read/update command, possibly HSETNX
  4. only schedule the Job if HSETNX returns 1, 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants