How to make an asynchronous time counter/trigger?

Question:

I am writing a telegram bot using aiogram. The bot will be used by a lot of people and the bot has an order module.

The task of this module is to create orders that must be closed on time.

For example, the bot requests the date and time the order was closed, the user enters the date: 2022-08-17 and the time: 19:00. Therefore, the order will have to close on 2022-08-17 at 19:00.

Again, we must take into account that there will be many such orders and I need some kind of optimized and asynchronous option for this task, thanks

Asked By: loldude

||

Answers:

I still went the standard way and so far there are no complaints, I also heard about the aioschedule library, something like a trigger. I myself have not used it, but if anyone is interested, you can read

date = datetime.datetime.strptime((order.dateStart + ' ' + order.timeStart), '%d.%m.%Y %H:%M')
await asyncio.sleep(timedelta.total_seconds(date - datetime.now()))
# code to be executed after the timer
Answered By: loldude
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.