Manager: mark worker as 'seen' when calling the WorkerState operation

Fix workers timing out when they're `asleep`. When sleeping, the Worker
will call the `WorkerState` operation to see if they have to wake up, but
that didn't mark the workers as "seen". As a result, a sleeping worker
would always time out.
This commit is contained in:
Sybren A. Stüvel 2022-07-18 17:56:56 +02:00
parent 63db0dc75c
commit bc725ea7dc
2 changed files with 41 additions and 0 deletions

View File

@ -180,8 +180,13 @@ func (f *Flamenco) SignOff(e echo.Context) error {
// (GET /api/worker/state)
func (f *Flamenco) WorkerState(e echo.Context) error {
logger := requestLogger(e)
worker := requestWorkerOrPanic(e)
if err := f.workerSeen(logger, worker); err != nil {
return sendAPIError(e, http.StatusInternalServerError, "error marking worker as 'seen'")
}
if worker.StatusRequested == "" {
return e.NoContent(http.StatusNoContent)
}

View File

@ -271,6 +271,42 @@ func TestWorkerSignoffStatusChangeRequest(t *testing.T) {
assertResponseNoContent(t, echo)
}
func TestWorkerState(t *testing.T) {
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
mf := newMockedFlamenco(mockCtrl)
worker := testWorker()
mf.persistence.EXPECT().WorkerSeen(gomock.Any(), &worker).Times(2)
// No state change requested.
{
echo := mf.prepareMockedRequest(nil)
requestWorkerStore(echo, &worker)
err := mf.flamenco.WorkerState(echo)
if assert.NoError(t, err) {
assertResponseNoContent(t, echo)
}
}
// State change requested.
{
requestStatus := api.WorkerStatusAsleep
worker.StatusChangeRequest(requestStatus, false)
echo := mf.prepareMockedRequest(nil)
requestWorkerStore(echo, &worker)
err := mf.flamenco.WorkerState(echo)
if assert.NoError(t, err) {
assertResponseJSON(t, echo, http.StatusOK, api.WorkerStateChange{
StatusRequested: requestStatus,
})
}
}
}
func TestWorkerStateChanged(t *testing.T) {
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()