feat: runtime manager
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"galaxy/rtmanager/internal/domain/operation"
|
||||
"galaxy/rtmanager/internal/service/restartruntime"
|
||||
"galaxy/rtmanager/internal/service/startruntime"
|
||||
)
|
||||
|
||||
// newRestartHandler returns the handler for
|
||||
// `POST /api/v1/internal/runtimes/{game_id}/restart`. The OpenAPI spec
|
||||
// declares no request body for this operation; any client-provided
|
||||
// body is ignored.
|
||||
func newRestartHandler(deps Dependencies) http.HandlerFunc {
|
||||
logger := loggerFor(deps.Logger, "internal_rest.restart")
|
||||
return func(writer http.ResponseWriter, request *http.Request) {
|
||||
if deps.RestartRuntime == nil {
|
||||
writeError(writer, http.StatusInternalServerError,
|
||||
startruntime.ErrorCodeInternal,
|
||||
"restart runtime service is not wired",
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
gameID, ok := extractGameID(writer, request)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
result, err := deps.RestartRuntime.Handle(request.Context(), restartruntime.Input{
|
||||
GameID: gameID,
|
||||
OpSource: resolveOpSource(request),
|
||||
SourceRef: requestSourceRef(request),
|
||||
})
|
||||
if err != nil {
|
||||
logger.ErrorContext(request.Context(), "restart runtime service errored",
|
||||
"game_id", gameID,
|
||||
"err", err.Error(),
|
||||
)
|
||||
writeError(writer, http.StatusInternalServerError,
|
||||
startruntime.ErrorCodeInternal,
|
||||
"restart runtime service failed",
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
if result.Outcome == operation.OutcomeFailure {
|
||||
writeFailure(writer, result.ErrorCode, result.ErrorMessage)
|
||||
return
|
||||
}
|
||||
|
||||
writeJSON(writer, http.StatusOK, encodeRuntimeRecord(result.Record))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user