fix: polylan sync

This commit is contained in:
2026-09-16 18:42:37 +02:00
parent 9ec9a54649
commit 4392122cfc
6 changed files with 107 additions and 25 deletions
+23 -2
View File
@@ -1,11 +1,20 @@
from datetime import timedelta
from django.tasks import task
from django.utils import timezone
from games.models import EventGame
from submissions.models import ImageCrop, SubmissionFile, OCRStatus
from submissions.services.aandt_sync import sync_event_game_scopes
from submissions.services.aandt_sync import (
AANDT_STATUS_IN_PROGRESS,
sync_event_game_scopes,
)
from PIL import Image
import pytesseract
# How often to repoll an EventGame's AAndT while it's still "in progress".
SCOPE_SYNC_REPOLL_INTERVAL = timedelta(seconds=15)
def _process_ocr_file(obj, file, crop: ImageCrop | None = None) -> bool:
if obj.ocr_status != OCRStatus.TO_PROCESS:
@@ -86,9 +95,21 @@ def sync_all_event_games_task():
@task
def sync_event_game_scopes_task(event_game_id: int):
"""Sync an EventGame's Scopes, repolling every minute while matches are in progress.
Each run re-checks the AAndT's status (from the `/` endpoint). While it's
still "in progress" (`7inprog`), the task re-enqueues itself with a delay
instead of relying on an external scheduler; once the status moves on, it
simply doesn't reschedule and the loop stops.
"""
event_game = EventGame.objects.filter(id=event_game_id).first()
if not event_game:
return
sync_event_game_scopes(event_game)
result = sync_event_game_scopes(event_game)
if result.status == AANDT_STATUS_IN_PROGRESS:
sync_event_game_scopes_task.using(
run_after=timezone.now() + SCOPE_SYNC_REPOLL_INTERVAL
).enqueue(event_game_id)