implement Executor pattern

This commit is contained in:
2026-02-09 13:10:00 -05:00
parent 3c11a79252
commit f615b03794
6 changed files with 93 additions and 48 deletions

View File

@@ -12,6 +12,7 @@ import (
"strings"
"time"
"git.gentoo.party/sam/thanks/internal/executor"
"git.gentoo.party/sam/thanks/internal/zfs"
)
@@ -35,15 +36,13 @@ type BackupJob struct {
Recursive bool `yaml:"recursive"` // create recursive snapshots
Prefix string `yaml:"prefix"` // name each snapshot with this prefix
Hooks BackupHooks `yaml:"hooks"` // external programs (libnotify, sendmail, etc) to call
localExecutor executor.Executor
remoteExecutor executor.Executor
}
// func (j *BackupJob) getBaseSnap() {
// params := "zfs get -j -d 1 -t snapshot guid,creation %s"
// srcCmd := fmt.Sprintf(params, j.Source)
// dstCmd := fmt.Sprintf(params, j.Target)
// }
func (j *BackupJob) listSnapshots(ctx context.Context) ([]zfs.Snapshot, error) {
allSnaps, err := zfs.Snapshots(ctx, j.Source)
allSnaps, err := zfs.Snapshots(ctx, j.localExecutor, j.Source)
if err != nil {
return nil, err
}
@@ -60,7 +59,6 @@ func (j *BackupJob) listSnapshots(ctx context.Context) ([]zfs.Snapshot, error) {
}
func (j *BackupJob) snapName() string {
// ts := time.Now().Format(time.RFC3339)
ts := time.Now().UnixMicro()
if j.Prefix == "" {
return fmt.Sprintf("%d", ts)
@@ -72,16 +70,12 @@ func (j *BackupJob) snapName() string {
func (j *BackupJob) Snapshot(ctx context.Context) (string, error) {
snapName := j.snapName()
snap := fmt.Sprintf("%s@%s", j.Source, snapName)
out, err := zfs.Cmd(
err := zfs.CreateSnapshot(
ctx,
"zfs snapshot %s",
snap,
j.localExecutor,
j.Source,
snapName,
)
if err != nil {
log.Printf("zfs-snapshot: error: %s", out)
return snapName, nil
}
return snap, err
}
@@ -137,9 +131,9 @@ func (j *BackupJob) Retain(ctx context.Context) error {
return nil
}
// func (j *BackupJob) findCommonAnscestor(ctx context.Context) {
// localSnapshots, err := j.listSnapshots(ctx)
// }
func (j *BackupJob) findCommonAnscestor(ctx context.Context) {
localSnapshots, err := j.listSnapshots(ctx)
}
type HookErr struct {
message string