From 354fd29f9eb48917515c54128422bcb5745a261e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Thu, 9 Jun 2022 11:58:30 +0200 Subject: [PATCH] Manager: Start timeout counting as soon as Worker gets task assigned Set the task's "last touched" field in the database to "now" as soon as the task is assigned to a worker. --- internal/manager/api_impl/workers.go | 5 +++++ internal/manager/api_impl/workers_test.go | 1 + 2 files changed, 6 insertions(+) diff --git a/internal/manager/api_impl/workers.go b/internal/manager/api_impl/workers.go index bffb68bc..71cf5bc2 100644 --- a/internal/manager/api_impl/workers.go +++ b/internal/manager/api_impl/workers.go @@ -322,6 +322,11 @@ func (f *Flamenco) ScheduleTask(e echo.Context) error { f.taskLogAppendTimestamped(logger, dbTask, fmt.Sprintf("Task assigned to worker %s (%s)\n", worker.Name, worker.UUID)) + // Start timeout measurement as soon as the Worker gets the task assigned. + if err := f.workerPingedTask(e.Request().Context(), logger, dbTask); err != nil { + return sendAPIError(e, http.StatusInternalServerError, "internal error updating task for timeout calculation: %v", err) + } + // Convert database objects to API objects: apiCommands := []api.Command{} for _, cmd := range dbTask.Commands { diff --git a/internal/manager/api_impl/workers_test.go b/internal/manager/api_impl/workers_test.go index 2cc16dbd..ace58ec7 100644 --- a/internal/manager/api_impl/workers_test.go +++ b/internal/manager/api_impl/workers_test.go @@ -34,6 +34,7 @@ func TestTaskScheduleHappy(t *testing.T) { Job: &job, } mf.persistence.EXPECT().ScheduleTask(echo.Request().Context(), &worker).Return(&task, nil) + mf.persistence.EXPECT().TaskTouchedByWorker(echo.Request().Context(), &task) mf.logStorage.EXPECT().Write(gomock.Any(), job.UUID, task.UUID, "2022-06-09T11:14:41+02:00 Task assigned to worker дрон (e7632d62-c3b8-4af0-9e78-01752928952c)\n")