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

Is it possible to change the delay of a delayed job? #505

Closed
tanqhnguyen opened this issue Jan 29, 2015 · 6 comments
Closed

Is it possible to change the delay of a delayed job? #505

tanqhnguyen opened this issue Jan 29, 2015 · 6 comments
Labels

Comments

@tanqhnguyen
Copy link

I have a delayed job, but I want to increase the delay, is it possible to do that?

Here is what I am having:

Job.get(id, function(job){
  job.delay(newDelay).save(cb);
});

With the above code, the delay is still the same old value

@behrad
Copy link
Collaborator

behrad commented Jan 29, 2015

save is for newly created unsaved job objects...
I think this helps you:
job.delay(newDelay).update( cb )

@behrad behrad closed this as completed Jan 29, 2015
@behrad behrad reopened this Jan 29, 2015
@tanqhnguyen
Copy link
Author

Actually, when looking at the code, save seems to call update when job has id

https://github.com/LearnBoost/kue/blob/master/lib/queue/job.js#L642

@behrad
Copy link
Collaborator

behrad commented Jan 29, 2015

yes @laoshanlung you're right. I forgot that save has the gaurd against job.id :)
Is q:job:ID:delay key updated in redis? if delay gets updated on redis, our promotion sort command will sense it :)

@tanqhnguyen
Copy link
Author

I think you are storing the job data in a hash structure with key format q:job:ID and yes the delay key is updated but the queue is still counting down the job

@behrad
Copy link
Collaborator

behrad commented Jan 29, 2015

the promotion code is here https://github.com/LearnBoost/kue/blob/master/lib/kue.js#L141
which is sorting job:delayed zset based on job->delay key, you may want to find if it is a race between the promotion and you setting delay, or a bug in redis sort, or kue itself :)
But I kindof remember have tested this and it was working...

@tanqhnguyen
Copy link
Author

Ok I guess I know what is going on. My use case is that the first time when a user sends a message, I create a delayed job (10s), within that 10s if any other user sends another message I need to reset the timer of the previously created delayed job so that it starts counting down from 10 again

And because Kue uses created_at and delay to determine whether a job should be promoted or not. Therefore, updating delay alone is not enough, I need to set created_at to the new Date().getTime() as well so that Kue can reset the timer. My final code becomes something likes this (It works, but I will need to add some kind of control flow later - async for example)

Job.get(id, function(job){
  job.set('created_at', new Date().getTime());
  job.delay(newDelay).save(cb);
});

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

2 participants