defer end-of-operation events
This commit is contained in:
parent
32083ee51f
commit
f3d747f9e3
@ -170,6 +170,22 @@ func (op *BackupOperation) Run(ctx context.Context) (err error) {
|
||||
events.BackupID: op.Results.BackupID,
|
||||
})
|
||||
|
||||
defer func() {
|
||||
op.bus.Event(
|
||||
ctx,
|
||||
events.BackupEnd,
|
||||
map[string]any{
|
||||
events.BackupID: op.Results.BackupID,
|
||||
events.DataStored: op.Results.BytesUploaded,
|
||||
events.Duration: op.Results.CompletedAt.Sub(op.Results.StartedAt),
|
||||
events.EndTime: dttm.Format(op.Results.CompletedAt),
|
||||
events.Resources: op.Results.ResourceOwners,
|
||||
events.Service: op.Selectors.PathService().String(),
|
||||
events.StartTime: dttm.Format(op.Results.StartedAt),
|
||||
events.Status: op.Status.String(),
|
||||
})
|
||||
}()
|
||||
|
||||
// -----
|
||||
// Execution
|
||||
// -----
|
||||
@ -871,19 +887,5 @@ func (op *BackupOperation) createBackupModels(
|
||||
return clues.Wrap(err, "creating backup model").WithClues(ctx)
|
||||
}
|
||||
|
||||
op.bus.Event(
|
||||
ctx,
|
||||
events.BackupEnd,
|
||||
map[string]any{
|
||||
events.BackupID: b.ID,
|
||||
events.DataStored: op.Results.BytesUploaded,
|
||||
events.Duration: op.Results.CompletedAt.Sub(op.Results.StartedAt),
|
||||
events.EndTime: dttm.Format(op.Results.CompletedAt),
|
||||
events.Resources: op.Results.ResourceOwners,
|
||||
events.Service: op.Selectors.PathService().String(),
|
||||
events.StartTime: dttm.Format(op.Results.StartedAt),
|
||||
events.Status: op.Status.String(),
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -212,6 +212,23 @@ func (op *RestoreOperation) do(
|
||||
events.RestoreID: opStats.restoreID,
|
||||
})
|
||||
|
||||
defer op.bus.Event(
|
||||
ctx,
|
||||
events.RestoreEnd,
|
||||
map[string]any{
|
||||
events.BackupID: op.BackupID,
|
||||
events.DataRetrieved: op.Results.BytesRead,
|
||||
events.Duration: op.Results.CompletedAt.Sub(op.Results.StartedAt),
|
||||
events.EndTime: dttm.Format(op.Results.CompletedAt),
|
||||
events.ItemsRead: op.Results.ItemsRead,
|
||||
events.ItemsWritten: op.Results.ItemsWritten,
|
||||
events.Resources: op.Results.ResourceOwners,
|
||||
events.RestoreID: opStats.restoreID,
|
||||
events.Service: op.Selectors.Service.String(),
|
||||
events.StartTime: dttm.Format(op.Results.StartedAt),
|
||||
events.Status: op.Status.String(),
|
||||
})
|
||||
|
||||
observe.Message(ctx, fmt.Sprintf("Discovered %d items in backup %s to restore", len(paths), op.BackupID))
|
||||
logger.Ctx(ctx).With("control_options", op.Options, "selectors", op.Selectors).Info("restoring selection")
|
||||
|
||||
@ -283,24 +300,6 @@ func (op *RestoreOperation) persistResults(
|
||||
|
||||
op.Results.ItemsWritten = opStats.gc.Successes
|
||||
|
||||
op.bus.Event(
|
||||
ctx,
|
||||
events.RestoreEnd,
|
||||
map[string]any{
|
||||
events.BackupID: op.BackupID,
|
||||
events.DataRetrieved: op.Results.BytesRead,
|
||||
events.Duration: op.Results.CompletedAt.Sub(op.Results.StartedAt),
|
||||
events.EndTime: dttm.Format(op.Results.CompletedAt),
|
||||
events.ItemsRead: op.Results.ItemsRead,
|
||||
events.ItemsWritten: op.Results.ItemsWritten,
|
||||
events.Resources: op.Results.ResourceOwners,
|
||||
events.RestoreID: opStats.restoreID,
|
||||
events.Service: op.Selectors.Service.String(),
|
||||
events.StartTime: dttm.Format(op.Results.StartedAt),
|
||||
events.Status: op.Status.String(),
|
||||
},
|
||||
)
|
||||
|
||||
return op.Errors.Failure()
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user