Files
archie/internal/daemon/builtin_jobs.go
T

46 lines
1.8 KiB
Go

package daemon
import (
"context"
"time"
"github.com/samcharles93/archie-core/internal/worktree"
)
// BuiltinJob is instance maintenance the daemon defines in code. The
// scheduler shows each as a locked schedule: it can be enabled, disabled,
// retimed and run now, but its work and ID are fixed here.
type BuiltinJob struct {
// ID is stable across releases; the scheduler keys its row on it.
ID string
Name string
// DefaultInterval is the schedule a new installation starts with.
DefaultInterval time.Duration
Run func(ctx context.Context) error
}
// mirrorIdle is how long a repository mirror no task clone borrows from
// survives before pruning; the next task for that repository rebuilds it.
const mirrorIdle = 7 * 24 * time.Hour
// BuiltinJobs lists the daemon's maintenance work. Binding dispatch and
// reaction draining are not here: they turn arrived events into tasks, so
// they stay on the intake tick rather than a schedule's coarser cadence.
func (d *Daemon) BuiltinJobs() []BuiltinJob {
return []BuiltinJob{
{ID: "volume-cleanup", Name: "Remove expired volumes", DefaultInterval: time.Hour, Run: d.cleanupExpiredStorage},
{ID: "issue-discovery", Name: "Discover forge issues", DefaultInterval: time.Minute, Run: d.poll},
{ID: "pr-reconcile", Name: "Reconcile pull requests", DefaultInterval: time.Minute, Run: d.reconcilePRs},
{ID: "pr-review-scan", Name: "Scan pull request reviews", DefaultInterval: time.Minute, Run: d.scanPRReviews},
{ID: "mirror-prune", Name: "Prune repository mirrors", DefaultInterval: 24 * time.Hour, Run: d.pruneMirrors},
}
}
func (d *Daemon) pruneMirrors(ctx context.Context) error {
removed, err := worktree.PruneMirrors(ctx, d.Cfg.Get().WorkDir, mirrorIdle, time.Now())
for _, mirror := range removed {
d.Log.InfoContext(ctx, "idle repository mirror removed", "path", mirror)
}
return err
}