sails-hook-tasks
v1.1.2
Published
SailsJS hook to run scheduled tasks
Downloads
88
Maintainers
Readme
sails-hook-tasks
SailsJS hook to run scheduled tasks
This hook leverages node-schedule to give you a clean and scalable way to register any number of scheduled tasks in your application.
Installation
$ npm install --save sails-hook-tasks
Usage
The hook will load any tasks found in api/tasks
with a filename like *Task.js
. e.g., api/tasks/MaintenanceTask.js
.
The task definition must include two functions:
schedule
attribute that defines the interval which this task will run at. For supported formats, refer to node-schedule.task()
the function that will be run at the defined interval.
Example:
// api/tasks/MaintenanceTask.js
module.exports = {
schedule: '*/10 * * * *',
task: function () {
// Do some maintenance here!
}
};
Configuration
You can optionally configure the hook by creating a configuration file at config/tasks.js
.
Currently, there are two supported configuration parameters.
active
: determines whether or not the hook will be loaded.eventsToWaitFor
: provide a list of events the hook shall wait for before loading itself.
You can copy this into config/tasks.js
if you want:
module.exports.tasks = {
// default: true
active: true,
eventsToWaitFor: []
// or:
// eventsToWaitFor: ['hook:orm:loaded', 'hook:customHook:loaded']
}
Tests
TODO
Contribute
Please do! Create an issue with any questions or submit a pull request.