ItsJohnB
ItsJohnB

Reputation: 71

Sails.js server bootstrap

I'm currently working with Sails.js and have hopefully a simple question for you. In this small project I work with auctions which end on a specific date.

My question is how can I make a "cron job look a like" which checks every auction end time.

I tried the following code:

var cronJob = require('cron').CronJob;
new cronJob('1 * * * * *', function(){
    console.log('You will see this message every second');
}, null, true, null);

The problem is when multiple users go to the page of the auction, multiple cronjobs will execute. Is there a way to make a bootstrap file in Sails.js after the start of the server or something like that?

Upvotes: 0

Views: 2198

Answers (1)

bredikhin
bredikhin

Reputation: 9025

There sure is: http://sailsjs.org/#!documentation/config.bootstrap. See bootstrap.js in your config folder.

That said, I'm not sure if using crons is the best way to handle it (resource consuming and inefficient), I would try organizing the code in an event-based manner instead.

Upvotes: 1

Related Questions