sails-hook-ohmytasks
Hook for running tasks before lift
In config/ohmytasks.js
toDo: //this is a list of tasks to be executed { } //function to be executed before task execution { } //function to execute on lifted event { } //function to be executed after task execution dirname: 'folder-with-tasks' //defaults to ohmytasks, place this dir under root folder
toDo expects a list of JSON's like this
tasks: 'name-of-task'
to be executed asynchronously or if tasks need to be executed in order:
tasks: 'task1' 'task2' ... order: true
the tasks are executed in the order specified in the list, and pass arguments to next task.
The name of each task refers to a file inside the folder specified in the config, each file should have the following structure:
module{ //task code // return callback(err, sails, other-args); // or // return callback(err); if order was not specified}
Example
In config/ohmytasks.js
moduleexportsohmytasks = toDo: tasks: 'task1' tasks: 'task2' 'task3' order: true { console; return ; } { console; } { console; return ; } dirname: 'ohmytasks'
with tasks definitions:
ohmytasks/task1.js
module{ console; return ;};
ohmytasks/task2.js
module{ console; return ;};
ohmytasks/task3.js
module{ console; console return ;};
The output will be something like:
----------- Loading config ----------- first task async task second task foo // error description i don't wanna lift
Since task2.js
returns an error, sails won't lift and will throw the error.
Notes
- This hook overrides
sails.config.bootstrap
so any logic there must be in one task or in before and after function definitions. - Only tasks inside the dirname folder will be loaded, other folders inside dirname will be ignored.