api/weldr: make composeToComposeEntry() take composeStatus
This makes all the calls to composeToComposeEntry() method slightly easier to read. Not a functional change.
This commit is contained in:
parent
5806e3ea08
commit
65c7b78d4e
2 changed files with 17 additions and 17 deletions
|
|
@ -1752,9 +1752,9 @@ func (api *API) composeQueueHandler(writer http.ResponseWriter, request *http.Re
|
|||
composeStatus := api.getComposeStatus(compose)
|
||||
switch composeStatus.State {
|
||||
case common.CWaiting:
|
||||
reply.New = append(reply.New, composeToComposeEntry(id, compose, common.CWaiting, composeStatus.Queued, composeStatus.Started, composeStatus.Finished, includeUploads))
|
||||
reply.New = append(reply.New, composeToComposeEntry(id, compose, composeStatus, includeUploads))
|
||||
case common.CRunning:
|
||||
reply.Run = append(reply.Run, composeToComposeEntry(id, compose, common.CRunning, composeStatus.Queued, composeStatus.Started, composeStatus.Finished, includeUploads))
|
||||
reply.Run = append(reply.Run, composeToComposeEntry(id, compose, composeStatus, includeUploads))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1836,7 +1836,7 @@ func (api *API) composeStatusHandler(writer http.ResponseWriter, request *http.R
|
|||
for _, id := range filteredUUIDs {
|
||||
if compose, exists := composes[id]; exists {
|
||||
composeStatus := api.getComposeStatus(compose)
|
||||
reply.UUIDs = append(reply.UUIDs, composeToComposeEntry(id, compose, composeStatus.State, composeStatus.Queued, composeStatus.Started, composeStatus.Finished, includeUploads))
|
||||
reply.UUIDs = append(reply.UUIDs, composeToComposeEntry(id, compose, composeStatus, includeUploads))
|
||||
}
|
||||
}
|
||||
sortComposeEntries(reply.UUIDs)
|
||||
|
|
@ -2140,7 +2140,7 @@ func (api *API) composeFinishedHandler(writer http.ResponseWriter, request *http
|
|||
if composeStatus.State != common.CFinished {
|
||||
continue
|
||||
}
|
||||
reply.Finished = append(reply.Finished, composeToComposeEntry(id, compose, common.CFinished, composeStatus.Queued, composeStatus.Started, composeStatus.Finished, includeUploads))
|
||||
reply.Finished = append(reply.Finished, composeToComposeEntry(id, compose, composeStatus, includeUploads))
|
||||
}
|
||||
sortComposeEntries(reply.Finished)
|
||||
|
||||
|
|
@ -2163,7 +2163,7 @@ func (api *API) composeFailedHandler(writer http.ResponseWriter, request *http.R
|
|||
if composeStatus.State != common.CFailed {
|
||||
continue
|
||||
}
|
||||
reply.Failed = append(reply.Failed, composeToComposeEntry(id, compose, common.CFailed, composeStatus.Queued, composeStatus.Started, composeStatus.Finished, includeUploads))
|
||||
reply.Failed = append(reply.Failed, composeToComposeEntry(id, compose, composeStatus, includeUploads))
|
||||
}
|
||||
sortComposeEntries(reply.Failed)
|
||||
|
||||
|
|
|
|||
|
|
@ -2,9 +2,9 @@ package weldr
|
|||
|
||||
import (
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
"github.com/osbuild/osbuild-composer/internal/common"
|
||||
"github.com/osbuild/osbuild-composer/internal/store"
|
||||
)
|
||||
|
|
@ -22,7 +22,7 @@ type ComposeEntry struct {
|
|||
Uploads []uploadResponse `json:"uploads,omitempty"`
|
||||
}
|
||||
|
||||
func composeToComposeEntry(id uuid.UUID, compose store.Compose, state common.ComposeState, queued, started, finished time.Time, includeUploads bool) *ComposeEntry {
|
||||
func composeToComposeEntry(id uuid.UUID, compose store.Compose, status *composeStatus, includeUploads bool) *ComposeEntry {
|
||||
var composeEntry ComposeEntry
|
||||
|
||||
composeEntry.ID = id
|
||||
|
|
@ -34,28 +34,28 @@ func composeToComposeEntry(id uuid.UUID, compose store.Compose, state common.Com
|
|||
composeEntry.Uploads = targetsToUploadResponses(compose.ImageBuild.Targets)
|
||||
}
|
||||
|
||||
switch state {
|
||||
switch status.State {
|
||||
case common.CWaiting:
|
||||
composeEntry.QueueStatus = common.IBWaiting
|
||||
composeEntry.JobCreated = float64(queued.UnixNano()) / 1000000000
|
||||
composeEntry.JobCreated = float64(status.Queued.UnixNano()) / 1000000000
|
||||
|
||||
case common.CRunning:
|
||||
composeEntry.QueueStatus = common.IBRunning
|
||||
composeEntry.JobCreated = float64(queued.UnixNano()) / 1000000000
|
||||
composeEntry.JobStarted = float64(started.UnixNano()) / 1000000000
|
||||
composeEntry.JobCreated = float64(status.Queued.UnixNano()) / 1000000000
|
||||
composeEntry.JobStarted = float64(status.Started.UnixNano()) / 1000000000
|
||||
|
||||
case common.CFinished:
|
||||
composeEntry.QueueStatus = common.IBFinished
|
||||
composeEntry.ImageSize = compose.ImageBuild.Size
|
||||
composeEntry.JobCreated = float64(queued.UnixNano()) / 1000000000
|
||||
composeEntry.JobStarted = float64(started.UnixNano()) / 1000000000
|
||||
composeEntry.JobFinished = float64(finished.UnixNano()) / 1000000000
|
||||
composeEntry.JobCreated = float64(status.Queued.UnixNano()) / 1000000000
|
||||
composeEntry.JobStarted = float64(status.Started.UnixNano()) / 1000000000
|
||||
composeEntry.JobFinished = float64(status.Finished.UnixNano()) / 1000000000
|
||||
|
||||
case common.CFailed:
|
||||
composeEntry.QueueStatus = common.IBFailed
|
||||
composeEntry.JobCreated = float64(queued.UnixNano()) / 1000000000
|
||||
composeEntry.JobStarted = float64(started.UnixNano()) / 1000000000
|
||||
composeEntry.JobFinished = float64(finished.UnixNano()) / 1000000000
|
||||
composeEntry.JobCreated = float64(status.Queued.UnixNano()) / 1000000000
|
||||
composeEntry.JobStarted = float64(status.Started.UnixNano()) / 1000000000
|
||||
composeEntry.JobFinished = float64(status.Finished.UnixNano()) / 1000000000
|
||||
default:
|
||||
panic("invalid compose state")
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue