diff --git a/internal/orchestrator/taskbackup.go b/internal/orchestrator/taskbackup.go index 69ae6e03..ca92b3b5 100644 --- a/internal/orchestrator/taskbackup.go +++ b/internal/orchestrator/taskbackup.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "slices" + "sync" "time" v1 "github.com/garethgeorge/backrest/gen/go/v1" @@ -113,10 +114,11 @@ func backupHelper(ctx context.Context, t Task, orchestrator *Orchestrator, plan Task: t.Name(), }) + var sendWg sync.WaitGroup lastSent := time.Now() // debounce progress updates, these can endup being very frequent. var lastFiles []string summary, err := repo.Backup(ctx, plan, func(entry *restic.BackupProgressEntry) { - + sendWg.Wait() if entry.MessageType == "status" { // prevents flickering output when a status entry omits the CurrentFiles property. Largely cosmetic. if len(entry.CurrentFiles) == 0 { @@ -144,14 +146,18 @@ func backupHelper(ctx context.Context, t Task, orchestrator *Orchestrator, plan zap.S().Warnf("unexpected message type %q in backup progress entry", entry.MessageType) } - if time.Since(lastSent) < 500*time.Millisecond { + if time.Since(lastSent) < 1*time.Second { return } lastSent = time.Now() - if err := orchestrator.OpLog.Update(op); err != nil { - zap.S().Errorf("failed to update oplog with progress for backup: %v", err) - } + sendWg.Add(1) + go func() { + if err := orchestrator.OpLog.Update(op); err != nil { + zap.S().Errorf("failed to update oplog with progress for backup: %v", err) + } + sendWg.Done() + }() }) vars := hook.HookVars{ diff --git a/internal/orchestrator/taskrestore.go b/internal/orchestrator/taskrestore.go index 2e6ca501..0eaf7a02 100644 --- a/internal/orchestrator/taskrestore.go +++ b/internal/orchestrator/taskrestore.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "sync" "time" v1 "github.com/garethgeorge/backrest/gen/go/v1" @@ -81,18 +82,26 @@ func (t *RestoreTask) Run(ctx context.Context) error { return fmt.Errorf("couldn't get repo %q: %w", t.restoreOpts.RepoId, err) } + var sendWg sync.WaitGroup lastSent := time.Now() // debounce progress updates, these can endup being very frequent. summary, err := repo.Restore(ctx, t.restoreOpts.SnapshotId, t.restoreOpts.Path, t.restoreOpts.Target, func(entry *v1.RestoreProgressEntry) { - if time.Since(lastSent) < 250*time.Millisecond { + sendWg.Wait() + if time.Since(lastSent) < 1*time.Second { return } lastSent = time.Now() zap.S().Infof("restore progress: %v", entry) + forgetOp.OperationRestore.Status = entry - if err := t.orch.OpLog.Update(op); err != nil { - zap.S().Errorf("failed to update oplog with progress for restore: %v", err) - } + + sendWg.Add(1) + go func() { + if err := t.orch.OpLog.Update(op); err != nil { + zap.S().Errorf("failed to update oplog with progress for restore: %v", err) + } + sendWg.Done() + }() }) if err != nil { return fmt.Errorf("restore failed: %w", err)