From ec5b3aac5206b028d3b046013171d2a7d2a19bfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Mon, 13 Jun 2022 14:19:47 +0200 Subject: [PATCH] Manager: on getting task update from Worker, write log before status change When receiving a `TaskUpdate` from a Worker, write to the task log, before handling any task status change. If both log and task status change are sent, the log will likely contain the cause of the task state change. Any subsequent task logs, for example generated by the Manager in response to the status change, should be logged after that. --- internal/manager/api_impl/workers.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/internal/manager/api_impl/workers.go b/internal/manager/api_impl/workers.go index ed7c0e6f..e375bdf9 100644 --- a/internal/manager/api_impl/workers.go +++ b/internal/manager/api_impl/workers.go @@ -414,6 +414,14 @@ func (f *Flamenco) doTaskUpdate( dbErrActivity = f.persist.SaveTaskActivity(ctx, dbTask) } + // Write the log first, because that's likely to contain the cause of the task + // state change. Any subsequent task logs, for example generated by the + // Manager in response to a status change, should be logged after that. + if update.Log != nil { + // Errors writing the log to disk are already logged by logStorage, and can be safely ignored here. + _ = f.logStorage.Write(logger, dbTask.Job.UUID, dbTask.UUID, *update.Log) + } + if update.TaskStatus != nil { oldTaskStatus := dbTask.Status err := f.stateMachine.TaskStatusChange(ctx, dbTask, *update.TaskStatus) @@ -427,11 +435,6 @@ func (f *Flamenco) doTaskUpdate( } } - if update.Log != nil { - // Errors writing the log to disk are already logged by logStorage, and can be safely ignored here. - _ = f.logStorage.Write(logger, dbTask.Job.UUID, dbTask.UUID, *update.Log) - } - // Any error updating the status is more important than an error updating the // activity. if dbErrStatus != nil {