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:
parent
63db0dc75c
commit
bc725ea7dc
@ -180,8 +180,13 @@ func (f *Flamenco) SignOff(e echo.Context) error {
|
|||||||
|
|
||||||
// (GET /api/worker/state)
|
// (GET /api/worker/state)
|
||||||
func (f *Flamenco) WorkerState(e echo.Context) error {
|
func (f *Flamenco) WorkerState(e echo.Context) error {
|
||||||
|
logger := requestLogger(e)
|
||||||
worker := requestWorkerOrPanic(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 == "" {
|
if worker.StatusRequested == "" {
|
||||||
return e.NoContent(http.StatusNoContent)
|
return e.NoContent(http.StatusNoContent)
|
||||||
}
|
}
|
||||||
|
@ -271,6 +271,42 @@ func TestWorkerSignoffStatusChangeRequest(t *testing.T) {
|
|||||||
assertResponseNoContent(t, echo)
|
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) {
|
func TestWorkerStateChanged(t *testing.T) {
|
||||||
mockCtrl := gomock.NewController(t)
|
mockCtrl := gomock.NewController(t)
|
||||||
defer mockCtrl.Finish()
|
defer mockCtrl.Finish()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user