Files
polylan-submitter/polylan_submitter/submissions/management/commands/sync_scopes.py
T

54 lines
1.8 KiB
Python

from django.core.management.base import BaseCommand, CommandError
from games.models import EventGame
from submissions.tasks import schedule_scope_sync, sync_all_event_games_task
class Command(BaseCommand):
help = "Queue a sync of Scopes (matches) and their assigned users from the legacy AAndT API."
def add_arguments(self, parser):
parser.add_argument(
"--event-game",
type=int,
default=None,
help=(
"Only queue a sync for the EventGame with this id. "
"Default: every EventGame with an AAndT token configured."
),
)
def handle(self, *args, **options):
event_game_id = options["event_game"]
if event_game_id is not None:
if not EventGame.objects.filter(id=event_game_id).exists():
raise CommandError(f"No EventGame with id={event_game_id}")
if schedule_scope_sync(event_game_id):
self.stdout.write(
self.style.SUCCESS(f"Started sync for EventGame {event_game_id}")
)
else:
self.stdout.write(
self.style.WARNING(
f"Sync already running for EventGame {event_game_id}"
)
)
return
if (
not EventGame.objects.exclude(apibot_token__isnull=True)
.exclude(apibot_token="")
.exists()
):
self.stdout.write(
self.style.WARNING("No EventGame has an AAndT token configured.")
)
return
sync_all_event_games_task.enqueue()
self.stdout.write(
self.style.SUCCESS("Queued sync for every EventGame with an AAndT token.")
)