Sails.js background processing loop, not related to connections -
if have process loop want run continuously after delays settimeout (regardless of connections) code go , executed from?
it looks code go in services directory, start loop? tried in app.js, doesn't work once sails lifted doesn't
simple example
// myfoo.js module.exports = { shouldfoo: true, dofoo: function(){ if(this.shouldfoo){ console.log('fooing ...'); settimeout(foo, 1000); } else { this.shutdownfoo(); } }, shutdownfoo: function(){ // finish process } }
then put:
var fooer = require('./api/services/myfoo.js'); fooer.dofoo();
you can use bootstrap.js
in config
folder (http://sailsjs.org/#!documentation/config.bootstrap):
module.exports.bootstrap = function (cb) { var fooer = require('./api/services/myfoo.js'); fooer.dofoo(); // it's important trigger callback method when finished // bootstrap! (otherwise server never lift, since it's waiting on bootstrap) cb(); };
Comments
Post a Comment