Answer the question
In order to leave comments, you need to log in
Telegram bot. How to implement parallel execution of tasks?
In general, I am writing a gaming telegram bot and ran into a problem. I want to implement the mechanics of moving from point A to point B, the transition takes some real time, say five minutes, and when these five minutes expire, the bot should send a notification to the user about arrival at the place (at the same time, other users can use the bot). Obviously, you need something that constantly checks against the value of the time allotted for the transition from A to B (the value in the database) and sends notifications to users when it expires. The first thing that came to mind was flows. But after all, if the bot terminates (the parent process), then all threads (the thread with the value check function) also terminate their work?
I ask you to suggest the direction in which it is worth moving in terms of solving this problem, thanks
Answer the question
In order to leave comments, you need to log in
I implemented this in this way:
The database stores the necessary values, once a minute (for example) a task is launched in celery, which searches the database for IDs of people to whom the bot should send some kind of notification. If there are any, then the list of these IDs is transmitted to the bot via the API, and the bot arranges the mailing list.
The bot itself was implemented according to the following scheme:
https://github.com/eternnoir/pyTelegramBotAPI/blob...
just added one more handle that accepts a POST request with a list of user IDs.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question