room seat cron backstop: expire_lapsed_room_seats sweeps idle mid-game tables — TDD
Phase 6 (final) of the room GATE VIEW + seat-renewal sprint. Cron backstop mirroring delete_stale_my_sea_draws — the lazy _expire_lapsed_seats already frees seats on every room/gate-view access, but a mid-game table nobody reopens past the grace window would keep its stuck seats forever. This command runs the same sweep over every room holding a timestamped FILLED slot. No flags; idempotent. Tests: ExpireLapsedRoomSeatsCommandTest (2) — frees a >2S lapsed seat + flags RENEWAL_DUE; no-op within grace. Full project suite 1590 ITs/UTs green. Code architected by Disco DeDisco <discodedisco@outlook.com> Git commit message Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
"""Auto-BYE gamers whose room seat token cost lapsed past the renewal grace.
|
||||
|
||||
The lazy `_expire_lapsed_seats` inside the room view / gatekeeper /
|
||||
gate-view already frees lapsed seats on every access; this command is the
|
||||
cron backstop for rooms nobody reopens — a mid-game table left idle past
|
||||
the grace window (filled_at + 2*renewal_period) would otherwise keep its
|
||||
stuck seats forever. Mirrors `delete_stale_my_sea_draws`. No flags;
|
||||
idempotent.
|
||||
|
||||
Usage:
|
||||
python manage.py expire_lapsed_room_seats
|
||||
"""
|
||||
from django.core.management.base import BaseCommand
|
||||
|
||||
from apps.epic.models import GateSlot, Room
|
||||
from apps.epic.views import _expire_lapsed_seats
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = "Free room seats whose token cost lapsed past the renewal grace."
|
||||
|
||||
def handle(self, *args, **options):
|
||||
rooms = Room.objects.filter(
|
||||
gate_slots__status=GateSlot.FILLED,
|
||||
gate_slots__filled_at__isnull=False,
|
||||
).distinct()
|
||||
freed = 0
|
||||
for room in rooms:
|
||||
before = room.gate_slots.filter(status=GateSlot.FILLED).count()
|
||||
_expire_lapsed_seats(room)
|
||||
if room.gate_slots.filter(status=GateSlot.FILLED).count() < before:
|
||||
freed += 1
|
||||
self.stdout.write(self.style.SUCCESS(
|
||||
f"Freed lapsed seats in {freed} room{'s' if freed != 1 else ''}."
|
||||
))
|
||||
Reference in New Issue
Block a user