Fix #99549: Remember Previous Status (#104217)

Fix #99549: When sending Workers offline, remember their previous status

When the status of a worker goes offline, the Manager will now make the status of the worker to be remembered once it goes back online. So when the Worker makes this status change (so for example `X → offline`), Manager should immediately set `StatusRequested = "X" ` once it goes online.

Reviewed-on: https://projects.blender.org/studio/flamenco/pulls/104217
This commit is contained in:
Eveline Anderson 2023-06-02 22:50:07 +02:00 committed by Sybren A. Stüvel
parent 2c163652c0
commit 4d2200bb0c
3 changed files with 23 additions and 8 deletions

View File

@ -13,9 +13,10 @@
}, },
"[yaml]": { "[yaml]": {
"editor.autoIndent": "keep", "editor.autoIndent": "keep",
"editor.defaultFormatter": "esbenp.prettier-vscode", "editor.defaultFormatter": "esbenp.prettier-vscode"
}, },
"[vue]": { "[vue]": {
"editor.defaultFormatter": "Vue.volar", "editor.defaultFormatter": "Vue.volar"
}, },
"editor.formatOnSave": true
} }

View File

@ -163,6 +163,11 @@ func (f *Flamenco) SignOff(e echo.Context) error {
w.StatusChangeClear() 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 // Pass a generic background context, as these changes should be stored even
// when the HTTP connection is aborted. // when the HTTP connection is aborted.
bgCtx, bgCtxCancel := bgContext() bgCtx, bgCtxCancel := bgContext()

View File

@ -244,6 +244,10 @@ func TestWorkerSignoffTaskRequeue(t *testing.T) {
Name: worker.Name, Name: worker.Name,
PreviousStatus: &prevStatus, PreviousStatus: &prevStatus,
Status: api.WorkerStatusOffline, Status: api.WorkerStatusOffline,
StatusChange: &api.WorkerStatusChangeRequest{
IsLazy: false,
Status: api.WorkerStatusAwake,
},
Updated: worker.UpdatedAt, Updated: worker.UpdatedAt,
Version: worker.Software, Version: worker.Software,
}) })
@ -255,11 +259,11 @@ func TestWorkerSignoffTaskRequeue(t *testing.T) {
assert.Equal(t, http.StatusNoContent, resp.StatusCode) assert.Equal(t, http.StatusNoContent, resp.StatusCode)
} }
func TestWorkerSignoffStatusChangeRequest(t *testing.T) { func TestWorkerRememberPreviousStatus(t *testing.T) {
mockCtrl := gomock.NewController(t) mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish() defer mockCtrl.Finish()
mf := newMockedFlamenco(mockCtrl) mf := newMockedFlamenco(mockCtrl)
worker := testWorker() worker := testWorker()
worker.Status = api.WorkerStatusAwake worker.Status = api.WorkerStatusAwake
worker.StatusChangeRequest(api.WorkerStatusOffline, true) worker.StatusChangeRequest(api.WorkerStatusOffline, true)
@ -269,25 +273,30 @@ func TestWorkerSignoffStatusChangeRequest(t *testing.T) {
Name: worker.Name, Name: worker.Name,
PreviousStatus: ptr(api.WorkerStatusAwake), PreviousStatus: ptr(api.WorkerStatusAwake),
Status: api.WorkerStatusOffline, Status: api.WorkerStatusOffline,
StatusChange: &api.WorkerStatusChangeRequest{
IsLazy: false,
Status: api.WorkerStatusAwake,
},
Updated: worker.UpdatedAt, Updated: worker.UpdatedAt,
Version: worker.Software, Version: worker.Software,
}) })
// Expect the Worker to be saved with the status change removed.
savedWorker := worker savedWorker := worker
savedWorker.Status = api.WorkerStatusOffline savedWorker.Status = api.WorkerStatusOffline
savedWorker.StatusChangeClear() savedWorker.StatusRequested = api.WorkerStatusAwake
savedWorker.LazyStatusRequest = false
mf.persistence.EXPECT().SaveWorkerStatus(gomock.Any(), &savedWorker).Return(nil) mf.persistence.EXPECT().SaveWorkerStatus(gomock.Any(), &savedWorker).Return(nil)
mf.stateMachine.EXPECT().RequeueActiveTasksOfWorker(gomock.Any(), &worker, "worker signed off").Return(nil) mf.stateMachine.EXPECT().RequeueActiveTasksOfWorker(gomock.Any(), &worker, "worker signed off").Return(nil)
mf.persistence.EXPECT().WorkerSeen(gomock.Any(), &worker) mf.persistence.EXPECT().WorkerSeen(gomock.Any(), &worker)
// Perform the request
echo := mf.prepareMockedRequest(nil) echo := mf.prepareMockedRequest(nil)
requestWorkerStore(echo, &worker) requestWorkerStore(echo, &worker)
err := mf.flamenco.SignOff(echo) err := mf.flamenco.SignOff(echo)
assert.NoError(t, err) assert.NoError(t, err)
assertResponseNoContent(t, echo) assertResponseNoContent(t, echo)
assert.Equal(t, api.WorkerStatusAwake, worker.StatusRequested)
assert.Equal(t, false, worker.LazyStatusRequest)
} }
func TestWorkerState(t *testing.T) { func TestWorkerState(t *testing.T) {