如何让我的 worker.js 访问 `sails` 对象 [英] How do I give my worker.js access to the `sails` object
本文介绍了如何让我的 worker.js 访问 `sails` 对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
根据 Heroku 对 worker dynos 的鼓励,我创建了一个 worker.js 文件在我的帆项目中.然而,这个文件是用 node worker.js
独立执行的,但我想重用我为我的风帆应用程序设置的配置.特别是sails.log
和sails 的模型.
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.
如何让我独立执行的 worker.js
文件访问 sails
对象.
How do I give my independently executed worker.js
file access to the sails
object.
推荐答案
经过大量的推特和询问,我终于用 sails.load()
解决了这个问题.基于此处的答案:
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();
});
这篇关于如何让我的 worker.js 访问 `sails` 对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文