V
V
vostotskiy2018-11-01 21:32:39
JavaScript
vostotskiy, 2018-11-01 21:32:39

How to properly schedule tasks in Node.JS?

Hello.
There is a project on the MEAN stack.
It is necessary to organize a notification system according to the schedule, sending notifications for certain users. The problem is that tasks need to be performed at a certain time, but not every day, but once every N days, the number N is stored in the database.
I found ready-made solutions in the form of a node-schedule for the notifications themselves, but did not find an approximate solution for my task (with the ability to configure which days to run).
The most primitive solution that I came up with is a node schedule, which, let's say, runs once a day at 00:00. It reads from the database the latest launch date and a pass (in how many days it needs to be launched). If the difference in days = recorded, then it starts, sends notifications to users, and then overwrites the last run date.
What do you think about such a decision?
Question. Perhaps someone came across a similar solution. How to implement such a launch?
Question2. Is it worth sculpting a scheduled launch in the "main" backend, or is it worth making a separate microservice on the same node that will "pull" the route of the main backend according to the schedule and send out notifications?
Thanks in advance

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Q
qq1, 2018-11-02
@qq1

Question. Perhaps someone came across a similar solution. How to implement such a launch?

You suggested quite a good solution, if you already have mongo, then you can use the agenda module instead of node-schedule, and get distributed job processing in addition.
It is better to separate into a separate process

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question