Dispo is a job and cronjob scheduler for Node.
It uses Kue as its job queue and Redis to store job data. Definition of recurring jobs is done using crontab syntax, one-off jobs can be queued using ZeroMQ requests.
All Jobs, regardless if running automatically or queued on demand for single runs, have to be defined in a configuration file. Jobs defined as cronjobs with a recurring interval are scheduled and run automatically.
> npm install dispo
Dispo provides a binary to start from the command line.
> node_modules/.bin/dispo -h
Usage: dispo [options]
Options:
-h, --help output usage information
-V, --version output the version number
-C, --config <config> config file path, default: `jobs.json`
-B, --basedir <basedir> directory used as a base for relative config and job paths
The --config
or -C
option is required and points to the relative path of the configuration file. If no configuration path is given, the configuration is expected to be in jobs.json
relative to the current working directory.
Jobs are defined in the jobs
property of the configuration file. Each job, identified using a name, must point its file
property to a JavaScript file exporting a function that is run when the job is executed.
The following configuration example defines a job called logRandomNumber
that can be queued on-demand and a recurring job called databaseCleanup
that is defined to run on 01:00 am every day using crontab syntax.
The attempts
property on the database cleanup job defines that the job is only attempted to run once. When the property is not explicitely set, it defaults to 3 so a job is retried twice on failure. When a recurringly scheduled job/cronjob reaches fails on each of its attempts, it is not automatically rescheduled.
{
"jobs": {
"logRandomNumber": {
"file": "jobs/logRandomNumber.js"
},
"databaseCleanup": {
"file": "jobs/databaseCleanup.js",
"cron": "0 1 * * * *",
"attempts": 1
}
}
}