Scheduling of Tasks

Asked

Viewed 332 times

0

I wonder if it is possible to schedule tasks with javascript, ie I have a javascript script and if it was possible to "clear" the 01:00 hour was run automatically.

I know that in other server language is possible, I’ve heard some people say that 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 that’s not possible, can you give me an idea of how to perform this procedure?

  • in javascript, you want for example a message to be displayed if the person is open?

  • @Alvaroalves, the message is not required, I need javascript to perform only the query via Get and do a procedure in the bank.

  • in this case you know that the client will need to have the browser tab open right? Because you do not make server side with PHP?

  • 1

    @Alvaroalves actually does yes server side, with NODE.js.

1 answer

0


You could use a setTimeout, calculating the time in milliseconds from the current moment to the moment of the task. ex: It’s 12:00 and I want to schedule an assignment for 1:00: 1h = 60min = 3600sec = 3600.000 Mili

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

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

The big problem in these methods is that they get logged in memory only, so if your server crashes, they won’t run. My suggestion is to create a table of scheduled tasks, and on server startup, list the tasks to run and schedule all using a script.

I hope I’ve helped.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.