mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-12 15:33:49 +00:00
feat(multiplayer): wire production proposal outbox delivery
This commit is contained in:
@@ -61,11 +61,13 @@ func main() {
|
||||
if *workloadSecret == "" {
|
||||
fmt.Fprintln(os.Stderr, "control-plane: warning: --workload-secret / COSMIC_CLASH_WORKLOAD_SECRET is unset; server registration and result submission will return 503")
|
||||
}
|
||||
server := &http.Server{Addr: *listen, Handler: newAPIHandler(db, *workloadSecret, candidateIndex), ReadHeaderTimeout: 5 * time.Second}
|
||||
service := newAPIService(db, *workloadSecret, candidateIndex)
|
||||
server := &http.Server{Addr: *listen, Handler: service.Handler(), ReadHeaderTimeout: 5 * time.Second}
|
||||
serveErr := make(chan error, 1)
|
||||
go func() { serveErr <- server.ListenAndServe() }()
|
||||
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
|
||||
defer stop()
|
||||
go api.RunProposalOutboxDispatcher(ctx, db, service)
|
||||
select {
|
||||
case err := <-serveErr:
|
||||
if err != nil && err != http.ErrServerClosed {
|
||||
@@ -81,11 +83,15 @@ func main() {
|
||||
}
|
||||
|
||||
func newAPIHandler(db *sql.DB, workloadSecret string, indexes ...api.CandidateIndex) http.Handler {
|
||||
return newAPIService(db, workloadSecret, indexes...).Handler()
|
||||
}
|
||||
|
||||
func newAPIService(db *sql.DB, workloadSecret string, indexes ...api.CandidateIndex) *api.Service {
|
||||
var candidateIndex api.CandidateIndex
|
||||
if len(indexes) > 0 {
|
||||
candidateIndex = indexes[0]
|
||||
}
|
||||
return (&api.Service{
|
||||
return &api.Service{
|
||||
SessionBackend: store.PostgresSessions{DB: db},
|
||||
SessionIssuer: store.PostgresSessions{DB: db},
|
||||
QueueBackend: store.PostgresQueue{DB: db},
|
||||
@@ -100,7 +106,7 @@ func newAPIHandler(db *sql.DB, workloadSecret string, indexes ...api.CandidateIn
|
||||
WorkloadVerify: api.WorkloadVerifierFromSignedToken([]byte(workloadSecret), db),
|
||||
Now: func() time.Time { return time.Now().UTC() },
|
||||
Log: logEvent,
|
||||
}).Handler()
|
||||
}
|
||||
}
|
||||
|
||||
// logEvent writes one credential-safe structured event per line to stderr.
|
||||
|
||||
Reference in New Issue
Block a user