Z
Z
zenondd2022-04-18 08:38:29
Python
zenondd, 2022-04-18 08:38:29

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 aioscheduleand 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

2 answer(s)
E
Elvis, 2022-04-18
@Dr_Elvis

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.

A
Alex Zeit, 2016-10-05
@idtimeless

Strange question => hands)
Layers + overlays + overlays + positioning + z-index

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question