vsivsi / meteor-job-collection

A persistent and reactive job queue for Meteor, supporting distributed workers that can run anywhere.
https://atmospherejs.com/vsivsi/job-collection
Other
385 stars 68 forks source link

Reschedule an existing job. #194

Closed agustinjch closed 8 years ago

agustinjch commented 8 years ago

Hello,

I want to change the schedule of an existing job, so, to create the job, what I do is:

newJob = QueueJobs.createJob(jobName, data) newJob.repeat({schedule:QueueJobs.later.parse.cron(schedule, true)}) newJob.save()

But, in order to change this schedule, what I've been trying is:

job = QueueJobs.getJob(jobId) job.repeat({schedule:QueueJobs.later.parse.cron(newSchedule, true)}) job.save()

But, after this it doesn't work, I mean, the schedule in the repeatWait is not changed. Do I have to cancel, remove the old job, and create a new one?

Thanks!

vsivsi commented 8 years ago

Hi, to change the schedule of a 'ready' or 'waiting' job, you need to pause it first, then make any changes and save them back.

https://github.com/vsivsi/meteor-job-collection#jcjobstatuspausable---anywhere https://github.com/vsivsi/meteor-job-collection#jobpauseoptions-callback---anywhere

agustinjch commented 8 years ago

Hello!

Thank you very much.

As an example, I'll write the code I finally used.

job = QueueJobs.getJob(jobId) job.pause() job.repeat({schedule:QueueJobs.later.parse.cron(newSchedule, true)}) job.save() job.resume()

Cheers!

vsivsi commented 8 years ago

Hi, great!

Note that the final job.resume() in your code above is unnecessary, and will probably fail, because running job.save() on a paused job assumes that you also want to resume it so that it is either 'waiting' or 'ready' when the save completes.