feat: publish matchmaking state events

This commit is contained in:
Josh Creek
2026-08-31 23:12:20 +01:00
parent 161d2cdceb
commit 60fe2caf8f
4 changed files with 76 additions and 3 deletions
+11 -2
View File
@@ -197,6 +197,7 @@ func (s *Service) queueCreate(w http.ResponseWriter, r *http.Request) {
writeDomainError(w, err)
return
}
s.publishTicketEvent(ticket, now)
writeJSON(w, http.StatusCreated, toQueueResponse(ticket))
return
}
@@ -225,6 +226,7 @@ func (s *Service) queueCreate(w http.ResponseWriter, r *http.Request) {
writeDomainError(w, err)
return
}
s.publishTicketEvent(ticket, now)
writeJSON(w, http.StatusCreated, toQueueResponse(ticket))
}
@@ -366,6 +368,7 @@ func (s *Service) queueMutation(w http.ResponseWriter, r *http.Request) {
writeDomainError(w, err)
return
}
s.publishTicketEvent(ticket, now)
if r.Header.Get("X-Contract-Delete") == "1" {
w.WriteHeader(http.StatusNoContent)
return
@@ -404,7 +407,10 @@ func (s *Service) proposalMutation(w http.ResponseWriter, r *http.Request) {
writeError(w, http.StatusNotFound, "not_found")
return
}
proposal.Expire(s.now())
now := s.now()
if proposal.Expire(now) {
s.publishProposalEvent(*proposal, now)
}
writeJSON(w, http.StatusOK, toProposalResponse(*proposal))
return
}
@@ -429,11 +435,13 @@ func (s *Service) proposalMutation(w http.ResponseWriter, r *http.Request) {
writeError(w, http.StatusNotFound, "not_found")
return
}
updated, err := proposal.Respond(playerID, key, parts[1] == "accept", revision, s.now())
now := s.now()
updated, err := proposal.Respond(playerID, key, parts[1] == "accept", revision, now)
if err != nil {
writeDomainError(w, err)
return
}
s.publishProposalEvent(updated, now)
writeJSON(w, http.StatusOK, toProposalResponse(updated))
}
@@ -465,6 +473,7 @@ func (s *Service) assignment(w http.ResponseWriter, r *http.Request) {
writeError(w, http.StatusServiceUnavailable, "assignment_unavailable")
return
}
_ = s.PublishControlPlaneEvent(ControlPlaneEvent{Event: "assignment_changed", Revision: 0, ResourceID: view.MatchID, OccurredAt: now, MatchID: view.MatchID, ServerID: view.ServerID, PlayerID: view.PlayerID})
writeJSON(w, http.StatusOK, view)
}