diff --git a/.vscode/settings.json b/.vscode/settings.json index 0856495c..0800dfa2 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -13,9 +13,10 @@ }, "[yaml]": { "editor.autoIndent": "keep", - "editor.defaultFormatter": "esbenp.prettier-vscode", + "editor.defaultFormatter": "esbenp.prettier-vscode" }, "[vue]": { - "editor.defaultFormatter": "Vue.volar", + "editor.defaultFormatter": "Vue.volar" }, + "editor.formatOnSave": true } diff --git a/internal/manager/api_impl/workers.go b/internal/manager/api_impl/workers.go index 99dbe7a4..6626992d 100644 --- a/internal/manager/api_impl/workers.go +++ b/internal/manager/api_impl/workers.go @@ -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() diff --git a/internal/manager/api_impl/workers_test.go b/internal/manager/api_impl/workers_test.go index d4d54db9..439fba41 100644 --- a/internal/manager/api_impl/workers_test.go +++ b/internal/manager/api_impl/workers_test.go @@ -244,6 +244,10 @@ func TestWorkerSignoffTaskRequeue(t *testing.T) { Name: worker.Name, PreviousStatus: &prevStatus, Status: api.WorkerStatusOffline, + StatusChange: &api.WorkerStatusChangeRequest{ + IsLazy: false, + Status: api.WorkerStatusAwake, + }, Updated: worker.UpdatedAt, Version: worker.Software, }) @@ -255,11 +259,11 @@ func TestWorkerSignoffTaskRequeue(t *testing.T) { assert.Equal(t, http.StatusNoContent, resp.StatusCode) } -func TestWorkerSignoffStatusChangeRequest(t *testing.T) { +func TestWorkerRememberPreviousStatus(t *testing.T) { mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() - mf := newMockedFlamenco(mockCtrl) + worker := testWorker() worker.Status = api.WorkerStatusAwake worker.StatusChangeRequest(api.WorkerStatusOffline, true) @@ -269,25 +273,30 @@ func TestWorkerSignoffStatusChangeRequest(t *testing.T) { Name: worker.Name, PreviousStatus: ptr(api.WorkerStatusAwake), Status: api.WorkerStatusOffline, + StatusChange: &api.WorkerStatusChangeRequest{ + IsLazy: false, + Status: api.WorkerStatusAwake, + }, Updated: worker.UpdatedAt, Version: worker.Software, }) - // Expect the Worker to be saved with the status change removed. 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) - // Perform the request echo := mf.prepareMockedRequest(nil) requestWorkerStore(echo, &worker) err := mf.flamenco.SignOff(echo) assert.NoError(t, err) assertResponseNoContent(t, echo) + + assert.Equal(t, api.WorkerStatusAwake, worker.StatusRequested) + assert.Equal(t, false, worker.LazyStatusRequest) } func TestWorkerState(t *testing.T) {