fix: correctly mark tasks as inprogress before execution

This commit is contained in:
garethgeorge
2024-01-04 18:12:50 -08:00
parent 55e4b22a74
commit 81ffb510e9
+3 -4
View File
@@ -84,6 +84,9 @@ func (t *TaskWithOperation) Cancel(withStatus v1.OperationStatus) error {
// timestamps are automatically added and the status is automatically updated if an error occurs.
func WithOperation(oplog *oplog.OpLog, op *v1.Operation, do func() error) error {
op.UnixTimeStartMs = curTimeMillis() // update the start time from the planned time to the actual time.
if op.Status == v1.OperationStatus_STATUS_PENDING || op.Status == v1.OperationStatus_STATUS_UNKNOWN {
op.Status = v1.OperationStatus_STATUS_INPROGRESS
}
if op.Id != 0 {
if err := oplog.Update(op); err != nil {
return fmt.Errorf("failed to add operation to oplog: %w", err)
@@ -93,10 +96,6 @@ func WithOperation(oplog *oplog.OpLog, op *v1.Operation, do func() error) error
return fmt.Errorf("failed to add operation to oplog: %w", err)
}
}
if op.Status == v1.OperationStatus_STATUS_PENDING || op.Status == v1.OperationStatus_STATUS_UNKNOWN {
op.Status = v1.OperationStatus_STATUS_INPROGRESS
}
err := do()
if err != nil {
op.Status = v1.OperationStatus_STATUS_ERROR