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.
This commit is contained in:
Sybren A. Stüvel 2022-06-13 14:19:47 +02:00
parent 25d5b01b3c
commit ec5b3aac52

View File

@ -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 {