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

Save() runs immediately as well #298

Closed
mirkods opened this issue Mar 9, 2016 · 7 comments
Closed

Save() runs immediately as well #298

mirkods opened this issue Mar 9, 2016 · 7 comments

Comments

@mirkods
Copy link

mirkods commented Mar 9, 2016

Hi there,
I'm having a strange behaviour, this is my code:

this.agenda.create(jobName, data)
    .unique({'data.eventId':eventId})
    .repeatEvery(cronString, {timezone:timezone})
    .save(function(err, job){
        res.send(200)
     })

Every time that a job is saved its define function is called immediately and then it respects its interval.
Why?

Cheers

@mirkods mirkods changed the title RepeatEvery runs immediately as well Save() runs immediately as well Mar 9, 2016
@mirkods
Copy link
Author

mirkods commented Mar 9, 2016

@rschmukler I think is strictly related with this #192

@jakeorr
Copy link
Contributor

jakeorr commented Mar 9, 2016

Hi @mirkods. You just need to call .computeNextRunAt() before saving:

this.agenda.create(jobName, data)
    .repeatEvery(cronString)
    .computeNextRunAt()
    .save(function () {});

@mirkods
Copy link
Author

mirkods commented Mar 10, 2016

Thanks @jakeorr!
I think could be useful to add this to the doc.

@mirkods mirkods closed this as completed Mar 15, 2016
@windmaomao
Copy link

windmaomao commented Jun 15, 2016

to be honest, i think .computeNextRunAt() should be the default case, because if you specify '1 16 * * 2,3,4,5,6', you don't expect it'll run right away.

FYI, 'in 4 minutes' does not trigger right away.

@demianhh
Copy link

frosted-develop.zip

@demianhh
Copy link

16-06-14-15-59-14-033_photo

@demianhh
Copy link

[this.agenda.create(jobName, data)
.repeatEvery(cronString)
.computeNextRunAt()
.save(function () {});

``](url)

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

No branches or pull requests

4 participants