Skip to content

Commit

Permalink
/take_message timeout improved
Browse files Browse the repository at this point in the history
  • Loading branch information
lavadk committed Apr 24, 2021
1 parent 84882d5 commit 8d31ae6
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion liker/command/handler_take_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def handle(self, context: CommandContext):
for msg in arr_messages:
try:
try:
iteration_begin = time.time()
# Verbose
if True:
if (n_processed > 0) and (n_processed % constants.TAKE_MESSAGE_VERBOSE_N == 0):
Expand All @@ -59,7 +60,12 @@ def handle(self, context: CommandContext):
message_id=msg.id,
reply_markup=new_reply_markup)
logger.debug(f'Took {channel_id} message {msg.id}, will sleep for {period:.1f} seconds')
time.sleep(period)

iteration_end = time.time()
iteration_remaining = period - (iteration_end - iteration_begin)
if iteration_remaining > 0:
logger.debug(f'Sleeping {iteration_remaining:.2f}')
time.sleep(iteration_remaining)
except ApiTelegramException as ex:
logger.exception(ex)
if ex.error_code == telegram_error.TOO_MANY_REQUESTS:
Expand Down

0 comments on commit 8d31ae6

Please sign in to comment.