From 147a69a7dfba5a5ad6d4a45dfd39a6e805121f83 Mon Sep 17 00:00:00 2001 From: Raz Date: Tue, 15 Apr 2025 12:11:53 +0200 Subject: [PATCH] fix ttc bugs --- tournaments/apps.py | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/tournaments/apps.py b/tournaments/apps.py index bcbf8fe..f27e90d 100644 --- a/tournaments/apps.py +++ b/tournaments/apps.py @@ -1,4 +1,7 @@ from django.apps import AppConfig +import logging + +logger = logging.getLogger(__name__) class TournamentsConfig(AppConfig): name = 'tournaments' @@ -9,16 +12,12 @@ class TournamentsConfig(AppConfig): # Start background tasks in production # Schedule background tasks on startup from django.conf import settings - if not settings.DEBUG: # Only in production - try: - from background_task.models import Task - from tournaments.tasks import check_confirmation_deadlines - - # Clear existing tasks first to avoid duplicates - Task.objects.filter(task_name='tournaments.tasks.check_confirmation_deadlines').delete() - - # Schedule the task to run every 30 minutes (1800 seconds) - check_confirmation_deadlines(repeat=settings.BACKGROUND_TASK_REPEAT_INTERVAL * 60) - except: - # Handle exceptions during startup - pass + # Prevent running during database migrations or tests + from django.core.management import call_command + try: + # Only schedule in production + if not settings.DEBUG: + # Use the management command to schedule tasks + call_command('schedule_tasks') + except Exception as e: + logger.error(f"Failed to schedule background tasks: {e}")