Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sails.js worker node without http endpoint

I am building a sails app that uses a RabbitMQ do delegate some tasks from the web requests to a worker node. This is pretty much the pattern described in https://devcenter.heroku.com/articles/background-jobs-queueing and https://github.com/heroku-examples/node-articles-nlp.

While I could do a sails.lift() in the worker node, it seems that it would be better to skip the http endpoint (express) and some grunt tasks (bower/frontend dependencies download, less, web resources copy to .tmp, ...).

Is there any way to achieve that?

Thanks!

Edit

I need sails in my worker so I can use the waterline ORM and the common services that are defined and exposed in sails.

like image 826
Manuel Darveau Avatar asked Dec 09 '14 03:12

Manuel Darveau


1 Answers

If you want to use the Sails ORM without the webserver and other web related components, you can use Sails Hooks to configure a minimal application

I wrote a full blog post about how I got background tasks working with SailsJS and Kue, but here's the main hooks part:

require('sails').load({
    hooks: {
        blueprints: false,
        controllers: false,
        cors: false,
        csrf: false,
        grunt: false,
        http: false,
        i18n: false,
        logger: false,
        //orm: leave default hook
        policies: false,
        pubsub: false,
        request: false,
        responses: false,
        //services: leave default hook,
        session: false,
        sockets: false,
        views: false
    }
}, function(err, app){

    //You can access all your SailsJS Models and Services here
    User.findOne(1).then(function(user){
        console.log(user)
    })
})
like image 106
Jason Kulatunga Avatar answered Sep 19 '22 11:09

Jason Kulatunga