Home > Back-end >  How to make an asynchronous time counter/trigger?
How to make an asynchronous time counter/trigger?

Time:08-17

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

CodePudding user response:

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
  • Related