SailsJS hook to run scheduled tasks
npm install sails-hook-tasksThis hook leverages node-schedule to give you a clean and scalable way to register any number of scheduled tasks in your application.
js
$ 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:
`js
// 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:`js
module.exports.tasks = {
// default: true
active: true,
eventsToWaitFor: []
// or:
// eventsToWaitFor: ['hook:orm:loaded', 'hook:customHook:loaded']
}
``