From b186ea18283963ece401750eaa823480cc976b7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Thu, 9 Jun 2022 10:57:52 +0200 Subject: [PATCH] Manager: write to task log when assigning it to a worker --- FEATURES.md | 1 + internal/manager/api_impl/workers.go | 7 +++++++ internal/manager/api_impl/workers_test.go | 3 +++ 3 files changed, 11 insertions(+) diff --git a/FEATURES.md b/FEATURES.md index 3113fb6e..b96d8367 100644 --- a/FEATURES.md +++ b/FEATURES.md @@ -54,6 +54,7 @@ Note that list is **not** in any specific order. - [ ] Jobs - [ ] Tasks +- [x] Let Manager write to task log when it's assigned to a worker. - [ ] Worker sleep schedule - [ ] Loading of job compiler scripts from disk - [ ] CLI option to write built-in job compiler scripts to disk diff --git a/internal/manager/api_impl/workers.go b/internal/manager/api_impl/workers.go index 5870f0b2..b94631c1 100644 --- a/internal/manager/api_impl/workers.go +++ b/internal/manager/api_impl/workers.go @@ -318,6 +318,13 @@ func (f *Flamenco) ScheduleTask(e echo.Context) error { return e.NoContent(http.StatusNoContent) } + // Add a note to the task log about the worker assignment. + err = f.logStorage.Write(logger, dbTask.Job.UUID, dbTask.UUID, + fmt.Sprintf("Task assigned to worker %s (%s)", worker.Name, worker.UUID)) + if err != nil { + logger.Error().Err(err).Msg("error writing to task log") + } + // 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 81c7b196..f3257fd0 100644 --- a/internal/manager/api_impl/workers_test.go +++ b/internal/manager/api_impl/workers_test.go @@ -35,6 +35,9 @@ func TestTaskScheduleHappy(t *testing.T) { } mf.persistence.EXPECT().ScheduleTask(echo.Request().Context(), &worker).Return(&task, nil) + mf.logStorage.EXPECT().Write(gomock.Any(), job.UUID, task.UUID, + "Task assigned to worker дрон (e7632d62-c3b8-4af0-9e78-01752928952c)") + err := mf.flamenco.ScheduleTask(echo) assert.NoError(t, err)