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:
2026-05-06 11:52:17 +08:00
parent cf1ec7b1c6
commit f6089ac5fb
5 changed files with 39 additions and 20 deletions
+10 -10
View File
@@ -86,15 +86,15 @@ func (w *Worker) pollOnce(ctx context.Context) {
}
func (w *Worker) execute(ctx context.Context, job Job) {
w.opts.Log.Info("job.start", "id", job.ID, "type", job.Type, "attempt", job.Attempts)
w.opts.Log.Info("job.start", "job_id", job.ID, "job_type", job.Type, "attempt", job.Attempts)
start := w.opts.Clock.Now()
h, ok := w.handlers[job.Type]
if !ok {
if derr := w.repo.DeadLetter(ctx, job.ID, fmt.Sprintf("unknown job type: %s", job.Type)); derr != nil {
w.opts.Log.Error("job.dead_letter_write_failed", "id", job.ID, "err", derr.Error())
w.opts.Log.Error("job.dead_letter_write_failed", "job_id", job.ID, "err", derr.Error())
}
w.opts.Log.Error("job.dead_letter", "id", job.ID, "type", job.Type, "reason", "unknown_type")
w.opts.Log.Error("job.dead_letter", "job_id", job.ID, "job_type", job.Type, "reason", "unknown_type")
w.fireOnDeadLetter(ctx, job, errors.New("unknown job type: "+string(job.Type)))
return
}
@@ -102,10 +102,10 @@ func (w *Worker) execute(ctx context.Context, job Job) {
err := w.runHandler(ctx, h, job)
if err == nil {
if cerr := w.repo.Complete(ctx, job.ID); cerr != nil {
w.opts.Log.Error("job.complete_write_failed", "id", job.ID, "err", cerr.Error())
w.opts.Log.Error("job.complete_write_failed", "job_id", job.ID, "err", cerr.Error())
}
w.opts.Log.Info("job.complete",
"id", job.ID, "type", job.Type, "attempt", job.Attempts,
"job_id", job.ID, "job_type", job.Type, "attempt", job.Attempts,
"duration_ms", w.opts.Clock.Now().Sub(start).Milliseconds())
return
}
@@ -114,10 +114,10 @@ func (w *Worker) execute(ctx context.Context, job Job) {
if IsPermanent(err) || job.Attempts >= job.MaxAttempts {
msg := truncate(err.Error(), 2000)
if derr := w.repo.DeadLetter(ctx, job.ID, msg); derr != nil {
w.opts.Log.Error("job.dead_letter_write_failed", "id", job.ID, "err", derr.Error())
w.opts.Log.Error("job.dead_letter_write_failed", "job_id", job.ID, "err", derr.Error())
}
w.opts.Log.Error("job.dead_letter",
"id", job.ID, "type", job.Type, "attempts", job.Attempts, "err", msg)
"job_id", job.ID, "job_type", job.Type, "attempt", job.Attempts, "err", msg)
w.fireOnDeadLetter(ctx, job, err)
return
}
@@ -127,10 +127,10 @@ func (w *Worker) execute(ctx context.Context, job Job) {
next := w.opts.Clock.Now().Add(delay)
msg := truncate(err.Error(), 2000)
if ferr := w.repo.FailWithRetry(ctx, job.ID, next, msg); ferr != nil {
w.opts.Log.Error("job.fail_retry_write_failed", "id", job.ID, "err", ferr.Error())
w.opts.Log.Error("job.fail_retry_write_failed", "job_id", job.ID, "err", ferr.Error())
}
w.opts.Log.Warn("job.fail_retry",
"id", job.ID, "type", job.Type, "attempt", job.Attempts,
"job_id", job.ID, "job_type", job.Type, "attempt", job.Attempts,
"err", msg, "next_at", next.Format(time.RFC3339))
}
@@ -164,7 +164,7 @@ func (w *Worker) fireOnDeadLetter(ctx context.Context, job Job, err error) {
}
defer func() {
if r := recover(); r != nil {
w.opts.Log.Error("job.dead_letter_hook_panic", "id", job.ID, "panic", r)
w.opts.Log.Error("job.dead_letter_hook_panic", "job_id", job.ID, "panic", r)
}
}()
w.opts.OnDeadLetter(ctx, job, err)