问题
Following Heroku's encouragement to a worker dynos I created a worker.js file in my Sails project. However, this file is executed independently with a node worker.js
but i'd like to reuse the config I set up for my sails app. Specifically the sails.log
and sails' models.
How do I give my independently executed worker.js
file access to the sails
object.
回答1:
After tons of tweeting and asking around, I finally managed this with sails.load()
. Based on the answer here:
var Sails = require('sails');
Sails.load(function(err, sails) {
// At this point you have access to all your models, services, etc.
sails.log('Worker is ready');
fireJobListener();
});
来源:https://stackoverflow.com/questions/31866141/how-do-i-give-my-worker-js-access-to-the-sails-object