periodic task runner
This commit is contained in:
		
							
								
								
									
										21
									
								
								bots/management/commands/periodic_bots.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								bots/management/commands/periodic_bots.py
									
									
									
									
									
										Normal file
									
								
							| @@ -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) | ||||||
		Reference in New Issue
	
	Block a user