You've already forked agentic-coding-workflow
chore(jobs): align log keys + add prune no-op test + down-migration comment
Cross-cutting review polish: - worker.go: id/type → job_id/job_type; one stray attempts → attempt for consistency with the other 4 sites in the same file. - runners/workspace_fetch.go: ws_id → workspace_id (matches the dispatched notify.Message metadata key). - runners/worktree_prune.go: id → worktree_id (same reason). - runners/worktree_prune_test.go: add TestWorktreePrune_NoRowsIsNoOp for symmetry with the no-op tests in the other 4 runner test files. - migrations/0005_jobs.down.sql: comment that DROP TABLE jobs cascades to drop the three idx_jobs_* indexes automatically.
This commit is contained in:
@@ -75,7 +75,7 @@ func (r *WorkspaceFetch) Run(ctx context.Context) {
|
||||
func (r *WorkspaceFetch) fetchOne(ctx context.Context, t WorkspaceFetchTarget) {
|
||||
ok, err := r.repo.MarkSyncing(ctx, t.ID)
|
||||
if err != nil {
|
||||
r.log.Error("workspace_fetch.mark_syncing", "ws_id", t.ID, "err", err.Error())
|
||||
r.log.Error("workspace_fetch.mark_syncing", "workspace_id", t.ID, "err", err.Error())
|
||||
return
|
||||
}
|
||||
if !ok {
|
||||
@@ -85,7 +85,7 @@ func (r *WorkspaceFetch) fetchOne(ctx context.Context, t WorkspaceFetchTarget) {
|
||||
if fetchErr := r.gitr.Fetch(ctx, t.MainPath, t.ID); fetchErr != nil {
|
||||
msg := truncate(fetchErr.Error(), 2000)
|
||||
if err := r.repo.MarkFetchResult(ctx, t.ID, false, msg); err != nil {
|
||||
r.log.Error("workspace_fetch.mark_fail", "ws_id", t.ID, "err", err.Error())
|
||||
r.log.Error("workspace_fetch.mark_fail", "workspace_id", t.ID, "err", err.Error())
|
||||
return
|
||||
}
|
||||
if derr := r.disp.Dispatch(ctx, notify.Message{
|
||||
@@ -101,13 +101,13 @@ func (r *WorkspaceFetch) fetchOne(ctx context.Context, t WorkspaceFetchTarget) {
|
||||
},
|
||||
CreatedAt: time.Now().UTC(),
|
||||
}); derr != nil {
|
||||
r.log.Error("workspace_fetch.dispatch", "ws_id", t.ID, "err", derr.Error())
|
||||
r.log.Error("workspace_fetch.dispatch", "workspace_id", t.ID, "err", derr.Error())
|
||||
}
|
||||
r.log.Warn("workspace_fetch.failed", "ws_id", t.ID, "err", msg)
|
||||
r.log.Warn("workspace_fetch.failed", "workspace_id", t.ID, "err", msg)
|
||||
return
|
||||
}
|
||||
if err := r.repo.MarkFetchResult(ctx, t.ID, true, ""); err != nil {
|
||||
r.log.Error("workspace_fetch.mark_ok", "ws_id", t.ID, "err", err.Error())
|
||||
r.log.Error("workspace_fetch.mark_ok", "workspace_id", t.ID, "err", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ func (r *WorktreePrune) warningPhase(ctx context.Context) {
|
||||
}
|
||||
for _, w := range rows {
|
||||
if err := r.repo.MarkPruneWarning(ctx, w.ID); err != nil {
|
||||
r.log.Error("worktree_prune.mark_warning", "id", w.ID, "err", err.Error())
|
||||
r.log.Error("worktree_prune.mark_warning", "worktree_id", w.ID, "err", err.Error())
|
||||
continue
|
||||
}
|
||||
if derr := r.disp.Dispatch(ctx, notify.Message{
|
||||
@@ -90,7 +90,7 @@ func (r *WorktreePrune) warningPhase(ctx context.Context) {
|
||||
},
|
||||
CreatedAt: time.Now().UTC(),
|
||||
}); derr != nil {
|
||||
r.log.Error("worktree_prune.dispatch", "id", w.ID, "err", derr.Error())
|
||||
r.log.Error("worktree_prune.dispatch", "worktree_id", w.ID, "err", derr.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -109,14 +109,14 @@ func (r *WorktreePrune) executionPhase(ctx context.Context) {
|
||||
continue
|
||||
}
|
||||
if rmErr := r.gitr.WorktreeRemove(ctx, started.MainPath, started.Path); rmErr != nil {
|
||||
r.log.Error("worktree_prune.remove_failed", "id", w.ID, "err", rmErr.Error())
|
||||
r.log.Error("worktree_prune.remove_failed", "worktree_id", w.ID, "err", rmErr.Error())
|
||||
if rbErr := r.repo.FinishPruneRollback(ctx, w.ID); rbErr != nil {
|
||||
r.log.Error("worktree_prune.rollback", "id", w.ID, "err", rbErr.Error())
|
||||
r.log.Error("worktree_prune.rollback", "worktree_id", w.ID, "err", rbErr.Error())
|
||||
}
|
||||
continue
|
||||
}
|
||||
if err := r.repo.FinishPruneSuccess(ctx, w.ID); err != nil {
|
||||
r.log.Error("worktree_prune.finish_success", "id", w.ID, "err", err.Error())
|
||||
r.log.Error("worktree_prune.finish_success", "worktree_id", w.ID, "err", err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -155,6 +155,23 @@ func TestWorktreePrune_ExecutionFailureRollsBack(t *testing.T) {
|
||||
assert.Equal(t, "rollback", repo.finalized[id])
|
||||
}
|
||||
|
||||
func TestWorktreePrune_NoRowsIsNoOp(t *testing.T) {
|
||||
t.Parallel()
|
||||
repo := &fakeWorktreeRepo{} // both lists nil
|
||||
gitr := &fakePruner{}
|
||||
disp := &recordingDispatcher{}
|
||||
cfg := runners.WorktreePruneConfig{IdleThreshold: 7 * 24 * time.Hour, WarningLead: 3 * 24 * time.Hour}
|
||||
|
||||
r := runners.NewWorktreePrune(repo, gitr, disp, cfg, discardLogger())
|
||||
r.Run(context.Background())
|
||||
|
||||
assert.Empty(t, repo.markedWarning)
|
||||
assert.Empty(t, repo.tryStartCalled)
|
||||
assert.Empty(t, repo.finalized)
|
||||
assert.Zero(t, gitr.calls)
|
||||
assert.Empty(t, disp.msgs)
|
||||
}
|
||||
|
||||
func TestWorktreePrune_CASLostSkipsSilently(t *testing.T) {
|
||||
t.Parallel()
|
||||
id := uuid.New()
|
||||
|
||||
Reference in New Issue
Block a user