Answer the question
In order to leave comments, you need to log in
How to execute a function with a certain frequency without resetting after restarting the program?
Good day! Wrote a Telegram bot on the library aiogram
. One of the functions of the bot is that after the user starts a certain process, the bot performs the necessary action every 2 hours and sends a notification to the user. To implement this functionality, I use the library aioschedule
and everything works fine, except for one moment - after the bot is restarted, all running cycles are reset. Is it possible to come up with an alternative solution to avoid this problem?
Answer the question
In order to leave comments, you need to log in
After each necessary action, add critical information to the database and rewrite your script so that it works with the database, then you will have up-to-date information at any time.
For example, you need to add 3 every 2 hours to what you added before. Then store the result in the database and the time of the last call (if you need to wait 2 hours independent of each other). When you start the bot, you take data from the database and start with these values. In the course of work - you update these values in base.
I hope the train of thought is clear, further creativity.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question