-
-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial long running command support
- Loading branch information
1 parent
2876278
commit f455a17
Showing
4 changed files
with
81 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package tasks | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"time" | ||
|
||
v1 "github.com/garethgeorge/backrest/gen/go/v1" | ||
) | ||
|
||
func NewOneoffForgetSnapshotTask(repoID, planID string, flowID int64, at time.Time, snapshotID string) Task { | ||
Check failure on line 11 in internal/orchestrator/tasks/taskruncommand.go
|
||
return &GenericOneoffTask{ | ||
OneoffTask: OneoffTask{ | ||
BaseTask: BaseTask{ | ||
TaskType: "forget_snapshot", | ||
TaskName: fmt.Sprintf("forget snapshot %q for plan %q in repo %q", snapshotID, planID, repoID), | ||
TaskRepoID: repoID, | ||
TaskPlanID: planID, | ||
}, | ||
FlowID: flowID, | ||
RunAt: at, | ||
ProtoOp: &v1.Operation{ | ||
Op: &v1.Operation_OperationForget{}, | ||
}, | ||
}, | ||
Do: func(ctx context.Context, st ScheduledTask, taskRunner TaskRunner) error { | ||
op := st.Op | ||
forgetOp := op.GetOperationForget() | ||
if forgetOp == nil { | ||
panic("forget task with non-forget operation") | ||
} | ||
|
||
if err := forgetSnapshotHelper(ctx, st, taskRunner, snapshotID); err != nil { | ||
taskRunner.ExecuteHooks(ctx, []v1.Hook_Condition{ | ||
v1.Hook_CONDITION_ANY_ERROR, | ||
}, HookVars{ | ||
Error: err.Error(), | ||
}) | ||
return err | ||
} | ||
return nil | ||
}, | ||
} | ||
} | ||
|
||
func runCommandHelper(ctx context.Context, st ScheduledTask, taskRunner TaskRunner, snapshotID string) error { | ||
t := st.Task | ||
|
||
repo, err := taskRunner.GetRepoOrchestrator(t.RepoID()) | ||
if err != nil { | ||
return fmt.Errorf("get repo %q: %w", t.RepoID(), err) | ||
} | ||
|
||
err = repo.UnlockIfAutoEnabled(ctx) | ||
if err != nil { | ||
return fmt.Errorf("auto unlock repo %q: %w", t.RepoID(), err) | ||
} | ||
|
||
if err := repo.ForgetSnapshot(ctx, snapshotID); err != nil { | ||
return fmt.Errorf("forget %q: %w", snapshotID, err) | ||
} | ||
|
||
taskRunner.ScheduleTask(NewOneoffIndexSnapshotsTask(t.RepoID(), time.Now()), TaskPriorityIndexSnapshots) | ||
taskRunner.OpLog().Delete(st.Op.Id) | ||
st.Op = nil | ||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters