From 29d8ff41c54981e75deba093ebef97bebc6f8917 Mon Sep 17 00:00:00 2001 From: Von Random Date: Mon, 6 Nov 2023 10:55:39 +0200 Subject: [PATCH] use asyncio.sleep instead of time.sleep in cron tasks --- pgbotlib/cron.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pgbotlib/cron.py b/pgbotlib/cron.py index f731731..1959293 100644 --- a/pgbotlib/cron.py +++ b/pgbotlib/cron.py @@ -1,4 +1,4 @@ -import time +import asyncio import random import yaml @@ -21,7 +21,8 @@ class Cron: tokens = frozenset(job['tokens'].split(',')) async def send_message() -> None: if 'rand' in job: - time.sleep(random.randint(0, job['rand']) * 60) + wait_seconds = random.randint(0, job['rand']) * 60 + await asyncio.sleep(wait_seconds) message = self.responder.get_response(tokens) message = self.responder.api_match(message, '') await self.client.send_message(job['chat'], message)