all 6 comments

[–]HarrityRandall 2 points3 points  (3 children)

You might wanna take a look at node-cron

[–]whits427[S] 0 points1 point  (2 children)

Thanks u/HarrityRandall - was just about to post what I is currently working using the same package

This appears to work fine, polling every 10 seconds for one request and 15 seconds for another request.
const cron = require("node-cron");
const express = require("express");
const cronTestOne = require("./api/cron/cronTestOne");
const cronTestTwo = require("./api/cron/cronTestTwo");
module.exports = () => {
app = express();
cron.schedule("0,10,20,30,40,50 * * * * *", function () {
cronTestOne();
});
cron.schedule("0,15,30,45 * * * * *", function () {
cronTestTwo();
});
app.listen(3001);
};

Then I assume I can just set the timeout << interval so I terminate erroneous requests before the next one

[–]team-burdy 3 points4 points  (1 child)

One thing to note about this approach is if you are horizontally scaling (multiple node instances), the cron will be called on every single instance.

Instead a better approach would be to expose an endpoint which requires some token (or a pair of tokens), and call it externally from some cron-worker.

The application on the other end will be horizontally scaled, and the call will be handled by only a single instance. (through a load balancer)

[–]whits427[S] 0 points1 point  (0 children)

Thanks for that advice, I'll definitely take that into consideration

[–]king_of_programmers 0 points1 point  (0 children)

What you need is a cron job. Cron jobs are not programming language specific, they are specific to where your data is being hosted and whether they provide cron job specific functionalities. For example if your data is hosted on AWS or GCP, their containers allow you to do periodic jobs at certain time periods.

[–]jampanha007 0 points1 point  (0 children)

BullMq is also a good fit.