hapi-job-queue
Hapi and MongoDB powered job queue.
Features:
- Utilizes server methods for jobs
- Jobs can be grouped together by name
- Jobs or groups can be run in intervals using the later cron and text syntax.
- Optional JSON api to control jobs
- Jobs contain tasks to run. By default a job has just one task with no data. Job will run once for each task.
Install:
npm install hapi-job-queue --save
Usage:
var server = ;var mongoUrl = 'mongodb://localhost:27017/something'; server; servermethod'emailUsers' { serverpluginsemailService;}; server;
Options:
connectionUrl
- mongodb connection urlendpoint
- Path for api endpoint. Set to false to disable. No trailing slash. (default: false)auth
- Auth strategy to use for api endpoints. (default: false)concurrentTasks
- Number of instances ofmethod
that can run simultaneously. Note: This is limited on a per job basis. Two jobs running at the same time will each have a max ofconcurrentTasks
. (default: 5)collection
- DB collection to use. (default: Jobs)verbose
- Extra logging. Taggedhapi-job-queue, info
. (default: true)jobs
- Array of job objects.name
- Name of the job. Used in api endpoints and methods.enabled
- Enables or disables a job.single
- Set to true if this job will be manually run and not on a timer. (default false)schedule
- (optional) Later style time definition.cron
- (optional) Later style cron definition.cronSeconds
- (optional) Use if the above cron setting is in seconds.method
- Method to run for each task or once when no tasks are assigned. Can be a hapi server method or a function.function(data, callback)
tasks
- (optional) Array of data to be passed to job method. Each item in the array will spawn an instance ofmethod
.
Methods:
These methods can be found in server.plugins.jobs
.
addJob
- params:job
,callback(err)
- Adds a job. Uses same job format as options.getJobs
- params:callback(err)
- Returns all jobsenableJob
- params:jobName
,callback(err)
- Enables a job.disableJob
- params:jobName
,callback(err)
- Disables a job.runSingle
- params:jobName
,tasks
,callback(err)
- Runs a single job. Tasks uses the same task format in options.
API
If you enable the web api these endpoints will be exposed.
GET /
- Returns all jobs.GET /enable/{jobName}
- Enables a jobGET /disable/{jobName}
- Disables a jobPOST /run/{jobName}
- Runs a job. Accepts a json payload of task data.