How do I give my worker.js access to the `sails` object

江枫思渺然 提交于 2019-12-11 12:54:53

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!