Fix workers immediately switching state on a lazy request

Fix an issue where workers would switch immediately on a state change
request, even if it was of the "after task is finished" kind.

The "may I keep running" endpoint wasn't checking the lazyness flag, and
thus any state change, lazy or otherwise, would interrupt the worker's
current task.
This commit is contained in:
Sybren A. Stüvel 2022-10-20 12:30:37 +02:00
parent ad0fea241d
commit e77bd9b841
3 changed files with 19 additions and 2 deletions

View File

@ -7,6 +7,7 @@ bugs in actually-released versions.
## 3.2 - in development ## 3.2 - in development
- When rendering EXR files, use Blender's preview JPEG files to generate the preview video ([43bc22f10fae](https://developer.blender.org/rF43bc22f10fae0fcaed6a4a3b3ace1be617193e21)). - When rendering EXR files, use Blender's preview JPEG files to generate the preview video ([43bc22f10fae](https://developer.blender.org/rF43bc22f10fae0fcaed6a4a3b3ace1be617193e21)).
- Fix issue where workers would switch immediately on a state change request, even if it was of the "after task is finished" kind.
## 3.1 - released 2022-10-18 ## 3.1 - released 2022-10-18

View File

@ -550,7 +550,7 @@ func (f *Flamenco) MayWorkerRun(e echo.Context, taskID string) error {
// mayWorkerRun checks the worker and the task, to see if this worker may keep running this task. // mayWorkerRun checks the worker and the task, to see if this worker may keep running this task.
func mayWorkerRun(worker *persistence.Worker, dbTask *persistence.Task) api.MayKeepRunning { func mayWorkerRun(worker *persistence.Worker, dbTask *persistence.Task) api.MayKeepRunning {
if worker.StatusRequested != "" { if worker.StatusRequested != "" && !worker.LazyStatusRequest {
return api.MayKeepRunning{ return api.MayKeepRunning{
Reason: "worker status change requested", Reason: "worker status change requested",
StatusChangeRequested: true, StatusChangeRequested: true,

View File

@ -465,7 +465,7 @@ func TestMayWorkerRun(t *testing.T) {
// Expect the worker to be marked as 'seen' regardless of whether it may run // Expect the worker to be marked as 'seen' regardless of whether it may run
// its current task or not, so equal to the number of calls to // its current task or not, so equal to the number of calls to
// `MayWorkerRun()` below. // `MayWorkerRun()` below.
mf.persistence.EXPECT().WorkerSeen(gomock.Any(), &worker).Times(4) mf.persistence.EXPECT().WorkerSeen(gomock.Any(), &worker).Times(5)
// Test: unhappy, task unassigned // Test: unhappy, task unassigned
{ {
@ -519,6 +519,22 @@ func TestMayWorkerRun(t *testing.T) {
StatusChangeRequested: true, StatusChangeRequested: true,
}) })
} }
// Test: happy, assigned and runnable; worker should go to bed after task is finished.
{
// Expect a 'touch' of the task.
mf.persistence.EXPECT().TaskTouchedByWorker(gomock.Any(), &task).Return(nil)
worker.StatusChangeRequest(api.WorkerStatusAsleep, true)
echo := prepareRequest()
task.WorkerID = &worker.ID
task.Status = api.TaskStatusActive
err := mf.flamenco.MayWorkerRun(echo, task.UUID)
assert.NoError(t, err)
assertResponseJSON(t, echo, http.StatusOK, api.MayKeepRunning{
MayKeepRunning: true,
})
}
} }
func TestTaskOutputProduced(t *testing.T) { func TestTaskOutputProduced(t *testing.T) {