cloudapi: return statuses as specified in openapi spec
Don't use common.State anymore, because it has different values from what's defined in openapi.yml. It makes sense to have these strings defined in the same package as the spec — ideally, the code generator would make them for us. While at it, add a "running" status. Fix the api.sh test to use these new statuses. Thanks to Ondřej Budai for an additional fix there.
This commit is contained in:
parent
f8c640c7ef
commit
31f4d9efe8
3 changed files with 32 additions and 5 deletions
|
|
@ -17,6 +17,13 @@ import (
|
|||
"github.com/osbuild/osbuild-composer/internal/worker"
|
||||
)
|
||||
|
||||
const (
|
||||
StatusPending = "pending"
|
||||
StatusRunning = "running"
|
||||
StatusSuccess = "success"
|
||||
StatusFailure = "failure"
|
||||
)
|
||||
|
||||
// Server represents the state of the cloud Server
|
||||
type Server struct {
|
||||
workers *worker.Server
|
||||
|
|
@ -212,10 +219,10 @@ func (server *Server) ComposeStatus(w http.ResponseWriter, r *http.Request, id s
|
|||
}
|
||||
|
||||
response := ComposeStatus{
|
||||
Status: status.State.ToString(), // TODO: map the status correctly
|
||||
Status: composeStatusFromJobStatus(status),
|
||||
ImageStatuses: &[]ImageStatus{
|
||||
{
|
||||
Status: status.State.ToString(), // TODO: map the status correctly
|
||||
Status: composeStatusFromJobStatus(status),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
@ -225,3 +232,23 @@ func (server *Server) ComposeStatus(w http.ResponseWriter, r *http.Request, id s
|
|||
panic("Failed to write response")
|
||||
}
|
||||
}
|
||||
|
||||
func composeStatusFromJobStatus(js *worker.JobStatus) string {
|
||||
if js.Canceled {
|
||||
return StatusFailure
|
||||
}
|
||||
|
||||
if js.Started.IsZero() {
|
||||
return StatusPending
|
||||
}
|
||||
|
||||
if js.Finished.IsZero() {
|
||||
return StatusRunning
|
||||
}
|
||||
|
||||
if js.Result.OSBuildOutput != nil && js.Result.OSBuildOutput.Success {
|
||||
return StatusSuccess
|
||||
}
|
||||
|
||||
return StatusFailure
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue