Kue Service
using the builing metaphor for this, all jobs have a site, this is where workers convene and are managed by a foreman. The Kue service has been wrapped to allow us to define a set of jobs in a site directory, each workers filenames match the job name, a .json file matching the workers name can be added to allow for settings and scheduling
NB - the queue-manager starts up a site, in a separate process - the idea is that we will allow for multiple processes to be run, in a cluster format in future, but for now if something goes wrong, ps -ef | grep node is your friend :)
thanks to the guys from kue and node-schedule for making this possible
installation
npm install kue-service --save
examples:
with directory structure:
test-site
|__workers
|__test.js
|__test.json
config.js
config.js:
var path = ; moduleexports = workerPath:__dirname + pathsep + 'workers'
test.js
{} TestWorkerprototype{ this__log; ;} TestWorkerprototype{ this__log; ;} TestWorkerprototype{ this__log; ;} TestWorkerprototype{ this__log; testjobdataaddedField = 'test'; ;} TestWorkerprototype{ ;} moduleexports = TestWorker;
test.json - what is of interest here is that you can configure jobs to run according to a schedule, to see the schedule params check out: github.com/node-schedule/node-schedule
{
"parameters":{
"test":"param"
},
"schedule":{
"params":{
"second":[0,5,10,15,20,25,30,35,40,45,50,55,60,65,70,75,80,85.90,95]
}
}
}
you start the service like so, this is from the unit test - shows how a scheduled job runs:
var KueService = ;//path to your test site foldervar config = site:__dirname + pathsep + 'test-sit'; kueService = ;var runCount = 0;kueServicestartconfig { if e return ; kueServicequeue; ; };
you kick off a job explicitly by calling the queue:
var KueService = ;var config = site:__dirname + pathsep + 'test-site'; kueService = ; kueServicestartconfig { if e return ; var job = kueServicequeue; job; job;};
Disclaimer and license
Use at own risk, MIT license