Created
February 1, 2016 00:55
-
-
Save PascalAnimateur/3d145205152e4637c078 to your computer and use it in GitHub Desktop.
Background process in Sails.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports.bootstrap = function(cb) { | |
sails.on('lifted', function() { | |
var someService = require('../api/services/SomeService.js'); | |
// Start background process of SomeService. | |
someService.startBackgroundProcess(); | |
}); | |
// It's very important to trigger this callback method when you are finished | |
// with the bootstrap! (otherwise your server will never lift, since it's waiting on the bootstrap) | |
cb(); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
shouldRun: true, | |
startBackgroundProcess: function(){ | |
if(this.shouldRun){ | |
console.log('Doing stuff...'); | |
setTimeout(this.startBackgroundProcess, 1000); | |
} else { | |
this.stopBackgroundProcess(); | |
} | |
}, | |
stopBackgroundProcess: function(){ | |
console.log('Stopped doing stuff.') | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment