Fix #99549: Remember Previous Status #104217

Merged
Sybren A. Stüvel merged 16 commits from Evelinealy/flamenco:web-api-upgrade into main 2023-06-02 22:50:10 +02:00
2 changed files with 16 additions and 8 deletions
Showing only changes of commit 15625ea001 - Show all commits

View File

@ -163,6 +163,11 @@ func (f *Flamenco) SignOff(e echo.Context) error {
w.StatusChangeClear()
}
// Remember the previous status if an initial status exists
if w.StatusRequested == "" {
w.StatusChangeRequest(prevStatus, false)
}
// Pass a generic background context, as these changes should be stored even
// when the HTTP connection is aborted.
bgCtx, bgCtxCancel := bgContext()

View File

@ -297,25 +297,28 @@ func TestWorkerRememberPreviousStatus(t *testing.T) {
worker := testWorker()
worker.Status = api.WorkerStatusTesting
initialStatusRequested := worker.StatusRequested
initialLazyStatusRequest := worker.LazyStatusRequest
worker.StatusChangeRequest(api.WorkerStatusOffline, true)
mf.broadcaster.EXPECT().BroadcastWorkerUpdate(api.SocketIOWorkerUpdate{
Id: worker.UUID,
Name: worker.Name,
PreviousStatus: ptr(api.WorkerStatusTesting),
PreviousStatus: ptr(api.WorkerStatusAwake),
Status: api.WorkerStatusOffline,
StatusChange: &api.WorkerStatusChangeRequest{
IsLazy: false,
Status: api.WorkerStatusAwake,
},
Updated: worker.UpdatedAt,
Version: worker.Software,
})
savedWorker := worker
savedWorker.Status = api.WorkerStatusOffline
savedWorker.StatusChangeClear()
savedWorker.StatusRequested = api.WorkerStatusAwake
savedWorker.LazyStatusRequest = false
mf.persistence.EXPECT().SaveWorkerStatus(gomock.Any(), &savedWorker).Return(nil)
mf.stateMachine.EXPECT().RequeueActiveTasksOfWorker(gomock.Any(), &worker, "worker signed off").Return(nil)
mf.persistence.EXPECT().WorkerSeen(gomock.Any(), &worker)
mf.stateMachine.EXPECT().RequeueActiveTasksOfWorker(gomock.Any(), gomock.Eq(&worker), "worker signed off").Return(nil)
mf.persistence.EXPECT().WorkerSeen(gomock.Any(), gomock.Eq(&worker))
worker.Status = api.WorkerStatusAwake
@ -325,8 +328,8 @@ func TestWorkerRememberPreviousStatus(t *testing.T) {
assert.NoError(t, err)
assertResponseNoContent(t, echo)
assert.Equal(t, initialStatusRequested, worker.StatusRequested)
assert.Equal(t, initialLazyStatusRequest, worker.LazyStatusRequest)
assert.Equal(t, api.WorkerStatusAwake, worker.StatusRequested)
assert.Equal(t, false, worker.LazyStatusRequest)
}
func TestWorkerState(t *testing.T) {