refac: atomic merge, lost-update race, RunPurge cost, duplicated walks

This commit is contained in:
Florian Sylvain committed 2026-10-21 22:47:46 +02:00
1 parent 0fc3511e2b
commit 074944c99a
45 files changed
+2204 -267

No files matched your search

+6 -6
View File
@@ -16,7 +16,7 @@ const (
)
type Job interface {
Tick(now time.Time) (purge.RunResult, bool, error)
Tick(ctx context.Context, now time.Time) (purge.RunResult, bool, error)
}
type CleanupJob interface {
@@ -24,15 +24,15 @@ type CleanupJob interface {
}
type task interface {
tick(now time.Time) (summary string, ran bool, err error)
tick(ctx context.Context, now time.Time) (summary string, ran bool, err error)
}
type purgeTask struct {
job Job
}
func (p purgeTask) tick(now time.Time) (string, bool, error) {
result, ran, err := p.job.Tick(now)
func (p purgeTask) tick(ctx context.Context, now time.Time) (string, bool, error) {
result, ran, err := p.job.Tick(ctx, now)
if errors.Is(err, purge.ErrPurgeBusy) {
return "", false, nil
}
@@ -44,7 +44,7 @@ type cleanupTask struct {
job CleanupJob
}
func (c cleanupTask) tick(now time.Time) (string, bool, error) {
func (c cleanupTask) tick(_ context.Context, now time.Time) (string, bool, error) {
result, ran, err := c.job.Tick(now)
return fmt.Sprintf("removed=%d", result.Removed), ran, err
}
@@ -119,7 +119,7 @@ func (r *Runner) tick(ctx context.Context) {
if ctx.Err() != nil {
return
}
summary, ran, err := r.task.tick(r.now())
summary, ran, err := r.task.tick(ctx, r.now())
if err != nil {
r.logger.Printf("scheduler: %s failed: %v", r.label, err)
return