persist match informtion in DB

This commit is contained in:
2026-11-09 22:07:37 +03:00
parent f48094cd55
commit f0616c7c51
4 changed files with 43 additions and 2 deletions
@@ -253,6 +253,24 @@ class MatchmakingService
exp: config.token_ttl.seconds.from_now.to_i
)
# Persist the match before finalizing in Redis: if the DB write fails,
# the players stay in "pending" and the sweep requeues them, so no
# match is announced without a corresponding DB record.
player1 = User.find(player1_id)
player2 = User.find(player2_id)
Match.create!(
uuid: match_id,
player1: player1,
player2: player2,
status: :ongoing,
game_server: config.game_server_url,
started_at: Time.current,
player1_rating_before: player1.rating,
player2_rating_before: player2.rating,
player1_rating_change: 0,
player2_rating_change: 0
)
payload = {
type: "matched",
match_id: match_id,