Scheduling as a Service, based on Agenda
Assuming all job types could be thought of as REST endpoints, scheduling could be offered as a service. agenda-rest
does just that, introduce a URL, name it, agenda-rest will call it on the times that you specify.
npm install -g agenda-rest
agenda-rest --dbhost localhost --dbname agenda
Get a list of defined jobs
- Method: GET
Defines a new category of jobs
- Method: POST
- Data:
{
name, // New job type's name
url, // koa-router style url
method, // (optional) Request type, default: POST
callback: { // (optional) to call with response after invocation
url,
method,
headers
}
}
Updates definition of a job category
- Method: PUT
- Data: same as POST
/api/job
Deletes job definition and cancels occurrences
- Method: DELETE
Schedule a job for single or multiple occurrences
- Method: POST
- Data:
{
name, // Name of the type to create the instance from
interval, // Interval in which job should be invoked (human-interval, can also be a date string for 'once')
data: { // (optional) default: {}
headers, // Http headers, e.g. { Authorization: '<token>' }
params, // Path parameters, to replace `:param` notations in job definition's url
query, // Query parameters (?foo=bar&baz=qux)
body // Accompanying data sent along the request
}
}
Callback, if present, would be invoked by the following object:
{
data: {
// passed data object, same as above
},
response // response from invocation
}
Like once
and every
, though without interval
. Executes the job now.
Cancels (not to be confused with 'delete') any jobs matching the query
- Method: POST
- Data: Mongo query
{
name: "foo"
}