|
|
|
|
@ -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}") |
|
|
|
|
|