1.1.2 • Published 10 years ago

sails-hook-tasks v1.1.2

Weekly downloads
10
License
MIT
Repository
github
Last release
10 years ago

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.

License

MIT

1.1.2

10 years ago

1.1.1

10 years ago

1.1.0

10 years ago

1.0.8

10 years ago

1.0.7

10 years ago

1.0.6

10 years ago

1.0.3

10 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago