perf(battlesnake): defer ordered lifecycle bookkeeping
Build and Push Docker Container / build-and-push (push) Successful in 10m12s

- Acknowledge start and end without waiting for persistence or dashboards.
- Keep runtime creation and finished-game removal on the response path.
- Serialize start, turn, and end bookkeeping per game in Quart tasks.
- Capture turn thinking before scheduling deferred persistence.
- Defer start metrics, logging, and stale-game pruning.
- Run legacy history exports in a worker thread.
- Record results and end metrics even when history export fails.
- Drain pending bookkeeping before closing storage during shutdown.
- Test sub-500 ms responses with slow backends and real SQLite.
- Cover event ordering, export failures, and rejected user agents.
This commit is contained in:
2026-11-03 10:38:20 +01:00
parent d4d6375e01
commit 4403978537
6 changed files with 242 additions and 33 deletions
+3
View File
@@ -21,6 +21,7 @@ from server.blueprints import (
create_metrics_blueprint,
create_dashboard_blueprint,
)
from server.services.game_lifecycle import GameLifecycleService
from server.services import (
DashboardEventsService,
DashboardWebSocketHub,
@@ -106,6 +107,7 @@ class Server:
self.app = Quart('Battlesnake', template_folder=os.path.join(data_path, 'templates', 'side'), static_folder=os.path.join(data_path, 'templates', 'files'))
self.game_lifecycle = GameLifecycleService(self)
self.app.register_blueprint(create_battlesnake_blueprint(self))
self.app.register_blueprint(create_metrics_blueprint(self))
self.app.register_blueprint(create_dashboard_blueprint(self))
@@ -143,6 +145,7 @@ class Server:
@self.app.after_serving
async def shutdown_state_storage():
await self.game_lifecycle.drain()
await self.dashboard_events_service.stop_listener()
await self.metrics_collector.close()
if self.gameplay_database is not None: