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 {