Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ a

This hook has been tested with sails 0.12.3

## Fork changes:

Added enviromentToRunIn to prevent running jobs in the main process.

## Install

npm install sails-hook-jobs
Expand Down Expand Up @@ -42,7 +46,8 @@ Copy this configurations file and save it to config/jobs.js
"processEvery": "10 seconds",
"maxConcurrency": 20,
"defaultConcurrency": 5,
"defaultLockLifetime": 10000
"defaultLockLifetime": 10000,
"enviromentToRunIn": "JOBS_RUNNER"
};

## How to define and schedule jobs
Expand Down
19 changes: 11 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ module.exports = function(sails) {
"maxConcurrency": 20,
"defaultConcurrency": 5,
"defaultLockLifetime": 10000,
// enables run this hook only inside a separete worker.
// "enviromentToRunIn": 'JOBS_RUNNER'
}
},

Expand All @@ -56,8 +58,10 @@ module.exports = function(sails) {
});
};

sails.on("lower", stopServer);
sails.on("lowering", stopServer);
if (config.enviromentToRunIn && sails.config.environment == config.enviromentToRunIn) {
sails.on("lower", stopServer);
sails.on("lowering", stopServer);
}

// Enable jobs using coffeescript
try {
Expand Down Expand Up @@ -97,12 +101,11 @@ module.exports = function(sails) {
eventsToWaitFor.push('hook:pubsub:loaded');

sails.after(eventsToWaitFor, function(){

// if (jobs.length > 0) {
// start agenda
agenda.start();
sails.log.verbose("sails jobs started");
// }
if (config.enviromentToRunIn && sails.config.environment == config.enviromentToRunIn) {
// start agenda
agenda.start();
sails.log.verbose("sails jobs started");
}

// Now we will return the callback and our hook
// will be usable.
Expand Down