Fix: Handle matches with active_status=False in _finalize_matches_with_results

- Remove active_status=True filter when finding pending matches with results
- Re-activate matches that had active_status=False (partially processed)
- This fixes match 426 being skipped because it had active_status=0
parent f40097d5
...@@ -485,9 +485,13 @@ class GamesThread(ThreadedComponent): ...@@ -485,9 +485,13 @@ class GamesThread(ThreadedComponent):
- Have start_time set but no end_time - Have start_time set but no end_time
- Have results and/or winning_outcomes already set - Have results and/or winning_outcomes already set
NOTE: This method also handles matches with active_status = False, which can
occur when a match was partially processed but the session crashed or had errors.
For such matches: For such matches:
- Set end_time to now - Set end_time to now
- Set status to 'done' - Set status to 'done'
- Set active_status to True (re-activate if it was False)
- Resolve associated bets based on the results - Resolve associated bets based on the results
Returns count of matches finalized. Returns count of matches finalized.
...@@ -497,9 +501,10 @@ class GamesThread(ThreadedComponent): ...@@ -497,9 +501,10 @@ class GamesThread(ThreadedComponent):
try: try:
# Find matches that have results but are still pending # Find matches that have results but are still pending
# Check for matches with result or winning_outcomes set # Check for matches with result or winning_outcomes set
# NOTE: We don't filter by active_status here because we want to catch
# matches that may have been partially processed (active_status = False)
pending_with_results = session.query(MatchModel).filter( pending_with_results = session.query(MatchModel).filter(
MatchModel.status == 'pending', MatchModel.status == 'pending',
MatchModel.active_status == True,
MatchModel.start_time.isnot(None), MatchModel.start_time.isnot(None),
MatchModel.end_time.is_(None), MatchModel.end_time.is_(None),
(MatchModel.result.isnot(None) | MatchModel.winning_outcomes.isnot(None)) (MatchModel.result.isnot(None) | MatchModel.winning_outcomes.isnot(None))
...@@ -523,6 +528,11 @@ class GamesThread(ThreadedComponent): ...@@ -523,6 +528,11 @@ class GamesThread(ThreadedComponent):
# Set status to done # Set status to done
match.status = 'done' match.status = 'done'
# Re-activate if it was False (handles partially processed matches)
if match.active_status == False:
logger.info(f"🔄 Re-activating match {match.match_number} (active_status was False)")
match.active_status = True
# Resolve associated bets # Resolve associated bets
self._resolve_match_bets(match, session) self._resolve_match_bets(match, session)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment