2

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.

Amin Shah Gilani
  • 8,675
  • 5
  • 37
  • 79
  • @TomSel could you please answer this question. I know you implemented something similar in March through http://stackoverflow.com/questions/29054652/using-node-cluster-module-with-sailsjs-eaddrinuse – Amin Shah Gilani Aug 06 '15 at 21:38

1 Answers1

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();
});
Community
  • 1
  • 1
Amin Shah Gilani
  • 8,675
  • 5
  • 37
  • 79