This package lets you easily push jobs onto a mongo-backed queue and have them asynchronously picked up and ran by a separate 'headless' meteor process.
meteor add differential:workers
Job.push new LoadRetentionJob
projectId: projectId
cohortInterval: "day"
class @LoadRetentionJob extends Job
handleJob: ->
project = Project.findOne @params.projectId
unless project
throw new Error "Project not found, could not load retention!"
Currently all methods are only available on the server.
job = new LoadRetentionJob projectId: projectId
Job.push (job, [options], [callback])
Extend the Job
class and implement the handleJob
method. The class name must end with Job
and be globally available. Classes ending in Job
are automatically registered to handle their corresponding jobs when they are dequeued. Inside your job handler this.params
will be the hash that you passed in as the parameter to new Job()
, and this.getMetadata(this.params._id)
will return additional information about the job in the queue used by monq. You can also run jobs on a cron schedule, rather than pushing them into the queue. To do this, just implement a static method setupCron(parser)
on your job class. We use percolate-studio's synced-cron package for scheduling. You will be passed a later.js parser
object as the only argument.
class @CleanUpJob extends Job
@setupCron: (parser) ->
parser.recur().on(0).hour()
handleJob: ->
doCleanUpStuff()
You can also implement afterJob
in your handler class. If an error is thrown in your handler, it will be passed in as the only argument to this function, otherwise it will be undefined
.
Uses Meteor.settings API.
{
"cluster": {
"count": 2
},
"workers": {
"count": 10,
"monq": {
// default monq parameters overrides
},
"cron": {
"log": false, // show SyncedCron logging
"disable": false // disable cron scheduler (nice for debugging sometimes)
}
},
}