Update templates

parent 3930037f
...@@ -873,6 +873,22 @@ class APIClient(ThreadedComponent): ...@@ -873,6 +873,22 @@ class APIClient(ThreadedComponent):
) )
self.message_bus.publish(response_message) self.message_bus.publish(response_message)
# Check if this is a successful fixture update that might trigger game start
if endpoint.name == 'fastapi_main' and processed_data.get('synchronized_matches', 0) > 0:
logger.info(f"Fixture update successful - {processed_data.get('synchronized_matches')} matches synchronized")
# Send a message to trigger game start check
game_start_check_message = Message(
type=MessageType.SYSTEM_STATUS,
sender=self.name,
data={
'status': 'fixture_update_completed',
'synchronized_matches': processed_data.get('synchronized_matches', 0),
'downloaded_zips': processed_data.get('downloaded_zips', 0),
'timestamp': datetime.utcnow().isoformat()
}
)
self.message_bus.publish(game_start_check_message)
logger.debug(f"API request successful: {endpoint.name}") logger.debug(f"API request successful: {endpoint.name}")
except Exception as e: except Exception as e:
...@@ -1051,7 +1067,7 @@ class APIClient(ThreadedComponent): ...@@ -1051,7 +1067,7 @@ class APIClient(ThreadedComponent):
current_interval = current_api_config.get("api_interval", 1800) # 30 minutes default current_interval = current_api_config.get("api_interval", 1800) # 30 minutes default
if not old_has_token and new_has_token: if not old_has_token and new_has_token:
# Token was added - start timer # Token was added - start timer and trigger immediate fixture update
fastapi_endpoint.enabled = True fastapi_endpoint.enabled = True
fastapi_endpoint.interval = current_interval fastapi_endpoint.interval = current_interval
fastapi_endpoint.retry_attempts = 10 fastapi_endpoint.retry_attempts = 10
...@@ -1061,6 +1077,10 @@ class APIClient(ThreadedComponent): ...@@ -1061,6 +1077,10 @@ class APIClient(ThreadedComponent):
logger.info(f"FastAPI timer started - token configured, {current_interval} second intervals enabled") logger.info(f"FastAPI timer started - token configured, {current_interval} second intervals enabled")
# Trigger immediate fixture update check
logger.info("Token configured - triggering immediate fixture update check")
self._execute_endpoint_request(fastapi_endpoint)
# Send immediate status update # Send immediate status update
status_message = Message( status_message = Message(
type=MessageType.SYSTEM_STATUS, type=MessageType.SYSTEM_STATUS,
...@@ -1069,7 +1089,8 @@ class APIClient(ThreadedComponent): ...@@ -1069,7 +1089,8 @@ class APIClient(ThreadedComponent):
"status": "timer_started", "status": "timer_started",
"endpoint": "fastapi_main", "endpoint": "fastapi_main",
"reason": "token_configured", "reason": "token_configured",
"interval_seconds": current_interval "interval_seconds": current_interval,
"immediate_update_triggered": True
} }
) )
self.message_bus.publish(status_message) self.message_bus.publish(status_message)
...@@ -1096,12 +1117,16 @@ class APIClient(ThreadedComponent): ...@@ -1096,12 +1117,16 @@ class APIClient(ThreadedComponent):
self.message_bus.publish(status_message) self.message_bus.publish(status_message)
elif old_has_token and new_has_token and old_token != new_token: elif old_has_token and new_has_token and old_token != new_token:
# Token was changed - keep timer running but reset failure count # Token was changed - keep timer running but reset failure count and trigger immediate update
fastapi_endpoint.consecutive_failures = 0 fastapi_endpoint.consecutive_failures = 0
fastapi_endpoint.last_request = None # Trigger immediate request with new token fastapi_endpoint.last_request = None # Trigger immediate request with new token
logger.info("FastAPI token updated - timer continues with new authentication") logger.info("FastAPI token updated - timer continues with new authentication")
# Trigger immediate fixture update check with new token
logger.info("Token updated - triggering immediate fixture update check with new token")
self._execute_endpoint_request(fastapi_endpoint)
except Exception as e: except Exception as e:
logger.error(f"Failed to handle token change: {e}") logger.error(f"Failed to handle token change: {e}")
......
...@@ -42,6 +42,7 @@ class GamesThread(ThreadedComponent): ...@@ -42,6 +42,7 @@ class GamesThread(ThreadedComponent):
self.message_bus.subscribe(self.name, MessageType.MATCH_START, self._handle_match_start) self.message_bus.subscribe(self.name, MessageType.MATCH_START, self._handle_match_start)
self.message_bus.subscribe(self.name, MessageType.PLAY_VIDEO_MATCH_DONE, self._handle_play_video_match_done) self.message_bus.subscribe(self.name, MessageType.PLAY_VIDEO_MATCH_DONE, self._handle_play_video_match_done)
self.message_bus.subscribe(self.name, MessageType.MATCH_DONE, self._handle_match_done) self.message_bus.subscribe(self.name, MessageType.MATCH_DONE, self._handle_match_done)
self.message_bus.subscribe(self.name, MessageType.SYSTEM_STATUS, self._handle_system_status)
# Send ready status # Send ready status
ready_message = MessageBuilder.system_status( ready_message = MessageBuilder.system_status(
...@@ -1313,6 +1314,33 @@ class GamesThread(ThreadedComponent): ...@@ -1313,6 +1314,33 @@ class GamesThread(ThreadedComponent):
except Exception as e: except Exception as e:
logger.error(f"Failed to handle MATCH_DONE message: {e}") logger.error(f"Failed to handle MATCH_DONE message: {e}")
def _handle_system_status(self, message: Message):
"""Handle SYSTEM_STATUS messages, particularly fixture update completion"""
try:
status = message.data.get("status")
if status == "fixture_update_completed":
synchronized_matches = message.data.get("synchronized_matches", 0)
downloaded_zips = message.data.get("downloaded_zips", 0)
logger.info(f"Fixture update completed: {synchronized_matches} matches synchronized, {downloaded_zips} ZIPs downloaded")
# Check if we should start a game now that fixtures are available
if synchronized_matches > 0 and not self.game_active:
logger.info("New fixtures available and no game is active - attempting to start game")
# Send START_GAME message to ourselves to trigger game start
start_game_message = Message(
type=MessageType.START_GAME,
sender=self.name,
recipient=self.name,
data={
"timestamp": time.time()
}
)
self.message_bus.publish(start_game_message)
except Exception as e:
logger.error(f"Failed to handle system status message: {e}")
def _set_match_status(self, match_id: int, status: str): def _set_match_status(self, match_id: int, status: str):
"""Set match status in database""" """Set match status in database"""
try: try:
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<html> <html>
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<title>Text Message Overlay</title> <title>MBetther system</title>
<style> <style>
* { * {
margin: 0; margin: 0;
...@@ -214,8 +214,8 @@ ...@@ -214,8 +214,8 @@
<div class="overlay-container"> <div class="overlay-container">
<div class="message-panel" id="messagePanel"> <div class="message-panel" id="messagePanel">
<div class="message-icon" id="messageIcon">📢</div> <div class="message-icon" id="messageIcon">📢</div>
<div class="message-title" id="messageTitle">Announcement</div> <div class="message-title" id="messageTitle">Mbetter Game</div>
<div class="message-content" id="messageContent">This is a custom message from the system.</div> <div class="message-content" id="messageContent">Waiting for game to start....</div>
</div> </div>
</div> </div>
......
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