From 0aaa78a638d1a9f902a6571bbab913233621a0da Mon Sep 17 00:00:00 2001 From: bakatrouble Date: Sun, 24 Nov 2019 19:33:27 +0300 Subject: [PATCH] periodic task runner --- bots/management/commands/periodic_bots.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 bots/management/commands/periodic_bots.py diff --git a/bots/management/commands/periodic_bots.py b/bots/management/commands/periodic_bots.py new file mode 100644 index 0000000..464ef9c --- /dev/null +++ b/bots/management/commands/periodic_bots.py @@ -0,0 +1,21 @@ +import traceback +from time import sleep + +import sentry_sdk +from django.core.management import BaseCommand + +from bots.models import TelegramBot + + +class Command(BaseCommand): + def handle(self, *args, **options): + while True: + for bot_instance in TelegramBot.objects.all(): + try: + bot_instance.run_periodic_task() + except KeyboardInterrupt: + return + except Exception as e: + sentry_sdk.capture_exception(e) + traceback.print_exc() + sleep(5)