Answer the question
In order to leave comments, you need to log in
How can I create a notification system in the task scheduler?
Good afternoon.
Task in detail: there is a task scheduler on node.js + mongoDB. A telegram is tied to them, through which at the moment you can add tasks. Additional functionality is needed in the form of notifications in a chat with a bot.
The question is: how can you track that it's time to throw a notification. Tried to tie up an interval for each event. However, with a large number of tasks, the bot crashes. When adding an event, I tried to sort by time and remember the time of the next one. The issue here is performance.
Who faced? Can you suggest an adequate algorithm for solving this problem?
Answer the question
In order to leave comments, you need to log in
In my opinion, your approach is fundamentally wrong.
1) When adding a new event, calculate its response time. Make an array of events. Once in a while, bypass the list and if the time for their execution has passed, then execute and delete them.
2) There is an Event Loop in JS and if you set a timeout of 5 seconds, this does not mean that it will be executed exactly after 5. Functions also have a run time.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question