Sails.js worker node without http endpoint

I am creating a sailing application that uses RabbitMQ, delegates some tasks from web requests to a working node. This is pretty much the template described at https://devcenter.heroku.com/articles/background-jobs-queueing and https://github.com/heroku-examples/node-articles-nlp .

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

Is there any way to achieve this?

Thanks!

Edit

I need the sails from my employee, so I can use the waterlogging system for the waterline and the general services that are defined and displayed in the sails.

+5
source share
2 answers

If you want to use Sails ORM without a web server and other related web 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 is the main part of the hooks:

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) }) }) 
+15
source

What exactly could you use sails.js in your working node? Sails.js is a web framework, you are not using your desktop for the Internet, at least not directly. Sails.js is not what you are looking for. MVC will not do you any good in this case, but you can definitely take advantage of its paradigm.

I have not used RabbitMQ with node.js yet, and I usually prefer redis as a message broker. I did something similar using kue . Kue is really focused on this task, and you can essentially define tasks in the same way as you would define a route in Express. This way, you can definitely create a controller to structure your logic, however Sails.js is not the right tool.

If you decide to use Sails.js, it's just because of its generator, you can surely take hold of your hands with grunts and yomen. It would not be very difficult. Another concept is to simply integrate your employees into their websites and simply limit the number of jobs for each worker. Kue supports this, and I got lucky with this, you just need to make sure that you are not doing a lot of processing or any processing that may take a long time, since you can start timing in this node network.

-1
source

Source: https://habr.com/ru/post/1208620/


All Articles