diff --git a/README.md b/README.md index d9d23bc..272a54f 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 diff --git a/index.js b/index.js index 271ce1c..bd859be 100644 --- a/index.js +++ b/index.js @@ -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' } }, @@ -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 { @@ -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.