0

I want my flask server to do a certain task when its idle for some time lets say 5 mins, i.e after 5 mins it will do another job. For this i need something to check if a server is busy or idle. How can I achieve this?

gg-dev-05
  • 353
  • 8
  • 14
  • Does this answer your question? [Background Worker with Flask](https://stackoverflow.com/questions/11256002/background-worker-with-flask) – Ken Kinder Jun 22 '20 at 19:03

1 Answers1

0

You can save the current datetime in a variable everytime a request is made via the @app.after_request annotation.

Then you need a routine to periodically check if the time difference between now and the saved timestamp is greater than 5 miutes. If so then run your task.

For executing your check every 5 minutes you may need some kind of scheduler which will be started with your application.