N
N
Nikita Dergachov2019-03-27 17:03:15
Node.js
Nikita Dergachov, 2019-03-27 17:03:15

How not to execute a request within 30 minutes?

Express sends a request to a third-party api to receive data and writes them to a file, how to make sure that the file is not updated within 30 minutes and a request is not sent to a third-party api?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
hzzzzl, 2019-03-27
@vanillathunder

let lastRequested = new Date()

if (new Date() - lastRequested > 1000 * 60 * 30) {  // 1000 мс * 60 сек * 30 мин
  lastRequested = new Date()
  // тут запрос
  //
  // а еще лучше обновить lastRequested = new Date()
  // когда запрос вернется успешно
  // чтобы в случае провала его можно было повторить быстрее чем через полчаса
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question