Manager: adjust code for WorkerStatusChangeRequest
extraction
See preceeding OpenAPI change.
This commit is contained in:
parent
9ca14cd471
commit
9ed6b6d931
@ -84,12 +84,12 @@ func (f *Flamenco) RequestWorkerStatusChange(e echo.Context, workerUUID string)
|
||||
// Store the status change.
|
||||
logger = logger.With().
|
||||
Str("status", string(dbWorker.Status)).
|
||||
Str("requested", string(change.StatusRequested)).
|
||||
Str("requested", string(change.Status)).
|
||||
Bool("lazy", change.IsLazy).
|
||||
Logger()
|
||||
|
||||
logger.Info().Msg("worker status change requested")
|
||||
dbWorker.StatusRequested = change.StatusRequested
|
||||
dbWorker.StatusRequested = change.Status
|
||||
dbWorker.LazyStatusRequest = change.IsLazy
|
||||
if err := f.persist.SaveWorker(e.Request().Context(), dbWorker); err != nil {
|
||||
logger.Error().Err(err).Msg("error saving worker after status change request")
|
||||
@ -111,8 +111,10 @@ func workerSummary(w persistence.Worker) api.WorkerSummary {
|
||||
Version: w.Software,
|
||||
}
|
||||
if w.StatusRequested != "" {
|
||||
summary.StatusRequested = &w.StatusRequested
|
||||
summary.LazyStatusRequest = &w.LazyStatusRequest
|
||||
summary.StatusChange = &api.WorkerStatusChangeRequest{
|
||||
Status: w.StatusRequested,
|
||||
IsLazy: w.LazyStatusRequest,
|
||||
}
|
||||
}
|
||||
return summary
|
||||
}
|
||||
|
@ -38,18 +38,20 @@ func TestFetchWorkers(t *testing.T) {
|
||||
workers := api.WorkerList{
|
||||
Workers: []api.WorkerSummary{
|
||||
{
|
||||
Id: worker1.UUID,
|
||||
Nickname: worker1.Name,
|
||||
Status: worker1.Status,
|
||||
StatusRequested: nil,
|
||||
Version: worker1.Software,
|
||||
Id: worker1.UUID,
|
||||
Nickname: worker1.Name,
|
||||
Status: worker1.Status,
|
||||
Version: worker1.Software,
|
||||
},
|
||||
{
|
||||
Id: worker2.UUID,
|
||||
Nickname: worker2.Name,
|
||||
Status: worker2.Status,
|
||||
StatusRequested: &worker2.StatusRequested,
|
||||
Version: worker2.Software,
|
||||
Id: worker2.UUID,
|
||||
Nickname: worker2.Name,
|
||||
Status: worker2.Status,
|
||||
Version: worker2.Software,
|
||||
StatusChange: &api.WorkerStatusChangeRequest{
|
||||
Status: worker2.StatusRequested,
|
||||
IsLazy: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
@ -110,11 +112,11 @@ func TestFetchWorker(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
assertResponseJSON(t, echo, http.StatusOK, api.Worker{
|
||||
WorkerSummary: api.WorkerSummary{
|
||||
Id: workerUUID,
|
||||
Nickname: "дрон",
|
||||
Version: "3.0",
|
||||
Status: api.WorkerStatusAwake,
|
||||
StatusRequested: &requestedStatus,
|
||||
Id: workerUUID,
|
||||
Nickname: "дрон",
|
||||
Version: "3.0",
|
||||
Status: api.WorkerStatusAwake,
|
||||
StatusChange: &api.WorkerStatusChangeRequest{Status: requestedStatus},
|
||||
},
|
||||
IpAddress: "fe80::5054:ff:fede:2ad7",
|
||||
Platform: "linux",
|
||||
@ -141,18 +143,20 @@ func TestRequestWorkerStatusChange(t *testing.T) {
|
||||
|
||||
// Expect a broadcast of the change
|
||||
mf.broadcaster.EXPECT().BroadcastWorkerUpdate(api.SocketIOWorkerUpdate{
|
||||
Id: worker.UUID,
|
||||
Nickname: worker.Name,
|
||||
Status: prevStatus,
|
||||
StatusRequested: &requestStatus,
|
||||
LazyStatusRequest: ptr(true),
|
||||
Updated: worker.UpdatedAt,
|
||||
Version: worker.Software,
|
||||
Id: worker.UUID,
|
||||
Nickname: worker.Name,
|
||||
Status: prevStatus,
|
||||
Updated: worker.UpdatedAt,
|
||||
Version: worker.Software,
|
||||
StatusChange: &api.WorkerStatusChangeRequest{
|
||||
Status: requestStatus,
|
||||
IsLazy: true,
|
||||
},
|
||||
})
|
||||
|
||||
echo := mf.prepareMockedJSONRequest(api.WorkerStatusChangeRequest{
|
||||
StatusRequested: requestStatus,
|
||||
IsLazy: true,
|
||||
Status: requestStatus,
|
||||
IsLazy: true,
|
||||
})
|
||||
err := mf.flamenco.RequestWorkerStatusChange(echo, workerUUID)
|
||||
assert.NoError(t, err)
|
||||
|
@ -94,9 +94,6 @@ func (f *Flamenco) SignOn(e echo.Context) error {
|
||||
if prevStatus != "" {
|
||||
update.PreviousStatus = &prevStatus
|
||||
}
|
||||
if w.StatusRequested != "" {
|
||||
update.StatusRequested = &w.StatusRequested
|
||||
}
|
||||
f.broadcaster.BroadcastWorkerUpdate(update)
|
||||
|
||||
resp := api.WorkerStateChange{}
|
||||
|
@ -99,13 +99,12 @@ func TestWorkerSignOn(t *testing.T) {
|
||||
prevStatus := worker.Status
|
||||
|
||||
mf.broadcaster.EXPECT().BroadcastWorkerUpdate(api.SocketIOWorkerUpdate{
|
||||
Id: worker.UUID,
|
||||
Nickname: "Lazy Boi",
|
||||
PreviousStatus: &prevStatus,
|
||||
Status: api.WorkerStatusStarting,
|
||||
StatusRequested: nil,
|
||||
Updated: worker.UpdatedAt,
|
||||
Version: "3.0-testing",
|
||||
Id: worker.UUID,
|
||||
Nickname: "Lazy Boi",
|
||||
PreviousStatus: &prevStatus,
|
||||
Status: api.WorkerStatusStarting,
|
||||
Updated: worker.UpdatedAt,
|
||||
Version: "3.0-testing",
|
||||
})
|
||||
|
||||
mf.persistence.EXPECT().SaveWorker(gomock.Any(), &worker).Return(nil)
|
||||
@ -206,13 +205,12 @@ func TestWorkerStateChanged(t *testing.T) {
|
||||
|
||||
// Expect a broadcast of the change
|
||||
mf.broadcaster.EXPECT().BroadcastWorkerUpdate(api.SocketIOWorkerUpdate{
|
||||
Id: worker.UUID,
|
||||
Nickname: worker.Name,
|
||||
PreviousStatus: &prevStatus,
|
||||
Status: api.WorkerStatusAwake,
|
||||
StatusRequested: nil,
|
||||
Updated: worker.UpdatedAt,
|
||||
Version: worker.Software,
|
||||
Id: worker.UUID,
|
||||
Nickname: worker.Name,
|
||||
PreviousStatus: &prevStatus,
|
||||
Status: api.WorkerStatusAwake,
|
||||
Updated: worker.UpdatedAt,
|
||||
Version: worker.Software,
|
||||
})
|
||||
|
||||
// Expect the Worker to be saved with the new status
|
||||
|
@ -22,8 +22,10 @@ func NewWorkerUpdate(worker *persistence.Worker) api.SocketIOWorkerUpdate {
|
||||
}
|
||||
|
||||
if worker.StatusRequested != "" {
|
||||
workerUpdate.StatusRequested = &worker.StatusRequested
|
||||
workerUpdate.LazyStatusRequest = &worker.LazyStatusRequest
|
||||
workerUpdate.StatusChange = &api.WorkerStatusChangeRequest{
|
||||
Status: worker.StatusRequested,
|
||||
IsLazy: worker.LazyStatusRequest,
|
||||
}
|
||||
}
|
||||
|
||||
return workerUpdate
|
||||
|
Loading…
x
Reference in New Issue
Block a user