Answer the question
In order to leave comments, you need to log in
How to implement deferred tasks in Node.js?
Hello!
I have the following task:
A person posts an application for some time and at the end of the time, for example, after 3 hours, it should automatically call a certain callback in time and pass the parameters there. This is necessary so that I can make an auto-selection of the winner.
Can you suggest which is better to use? Also the general principle of how to do it in Node.js.
Queues are built into Laravel and therefore there were no questions
Answer the question
In order to leave comments, you need to log in
Every N seconds, check the stack of your orders. If the system time is greater than the time specified in the request, then call the callback with this request and remove it from the stack, otherwise do nothing.
If on pure NodeJS, then you can stupidly hang setTimeout. But keep in mind that when the server is restarted, the tasks will not be saved, therefore, if safety is important, then put a copy somewhere in the database or on disk, and when executed, delete it from there or mark it as completed, when the server starts, resume those that have not been completed .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question