Task Scheduling [closed]

0

I would like to know if it is possible to schedule tasks with javascript, that is, I have a javascript script and if it were possible "of course" the 01:00 hour would be executed automatically.

I know this in other server languages is possible, I've heard some people saying that it uses javascript for server.

--request GET "{url}/1/RecurrentPayment/{RecurrentPaymentId}"
--header "Content-Type: application/json"
--header "MerchantId: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
--header "MerchantKey: 0123456789012345678901234567890123456789"
--header "RequestId: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
--data-binary
--verbose

If this is not possible, can you give me an idea how to do this?

    
asked by anonymous 30.10.2018 / 21:50

1 answer

0

You could use a setTimeout, calculating the time in milliseconds from the current time to the time of the task. ex: It's 12:00 and I want to schedule a task at 1:00 p.m.: 1h = 60min = 3600sec = 3600,000 mili

setTimeout(() => {
  console.log('Tarefa executada!!!!');
}, 3600000);

Remembering that setTimeout is asynchronous! For repetitive tasks, you can still run a setInterval, it will execute the task after X milliseconds.

The big problem with these methods is that they get registered in memory only, so if your server crashes, they will not run. My suggestion is to create a table of scheduled tasks, and at server startup, list the tasks to be executed and schedule them all using a script.

I hope I have helped.

    
01.11.2018 / 14:21