Answer the question
In order to leave comments, you need to log in
How to organize micro slips in a celery task?
Good day.
Actually the question is this.
I wrote a bot on aiogram + backend on django.
The bot performs mailing via telegram channels.
How it works:
In the bot, we receive a request to start the mailing list -> we process the request on the back and start the mailing list (of course, celery was chosen for this). The account that receives the command to send it starts to do it, but between each message I need to make an interval of 3 seconds and between every 100 messages 1000 seconds. (there may be several such parallel mailings)
the code looks something like this:
While True:
for g in groups[:100]:
send_message(g, msg)
time.sleep(3)
time.sleep(1000)
Answer the question
In order to leave comments, you need to log in
Move sending one message to one chat into a separate task. And in the second task, inside the loop, call these tasks with an ETA
some kind of global bucket is needed, if 10 mailings are launched at the same time, then there will not be 3 seconds of sleep between requests, even if you put them in each task. And on the basis of this global some kind of counter, you need to steer all mailings.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question