Akivamu
Akivamu

Reputation: 588

Implement infinite long running service in NodeJS

I have a list of URLs in DB. I want to periodically check if those URLs are alive or not.

So I create a long running service which run infinite loop, each iteration:

Please guide me how to implement that service.

I looked at Bull and Kue, but they seem not support infinite loop service?

Upvotes: 0

Views: 307

Answers (2)

Yogesh_D
Yogesh_D

Reputation: 18809

You can use something very simple like setInterval() to have your task repeat x amount of times.

var testUrls = function(){
    //do your magic of connecting to the DB and checking urls.
}

setInterval(testUrls, 60000);

The above code snippet will call your function testUrls every minute.

Or if you need more control over the scheduling you can use a npm package like cron.

Upvotes: 2

Dhirendra
Dhirendra

Reputation: 790

You can use node-schedule

Its very simple

var schedule = require('node-schedule');

var j = schedule.scheduleJob('42 * * * *', function(){
  console.log('The answer to life, the universe, and everything!');
});

Upvotes: 0

Related Questions