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
388 stars 68 forks source link

How to find a specific job so that we can change the delay? #236

Open suryaiiit opened 7 years ago

suryaiiit commented 7 years ago

Thanks for this wonderful package.

I've groups which has 'n' users. There can be multiple groups.. now for each Group I'm creating a JobQueue with a dynamic delay for every run, lets call this frequency.

const GroupJobs = JobCollection('groups');

job = new Job(GroupJobs, 'jobGroup', data);

GroupsJobs.processJobs('jobGroup', ...);

Everything works fine. Now I need to change the frequency of a specific (end-user defined) ... how can I do that?

157 - this tells me how to do, but how do I get the Job object??

vsivsi commented 7 years ago

Hi, a JobCollection is backed by a regular Meteor collection. So you can do a jc.find() query and return one or more job documents of interest. Then there are a couple of ways to turn those into Job objects. One is to individually call new Job(jc, doc) on each one. The other way is to just return an _id or array of _id values, and then either use jc.getJob() or jc.getJobs() to return job documents.

A more convenient approach is to define a transform for the job collection so finds alway return job objects. See for example: https://github.com/vsivsi/meteor-job-collection-playground/blob/master/play.coffee#L9