From 69c5831783c9f6b9636e96fb72892413dfae2506 Mon Sep 17 00:00:00 2001 From: Jerry Yan <792602257@qq.com> Date: Wed, 6 May 2026 11:10:29 +0800 Subject: [PATCH] fix(app): respect cfg.Jobs.ShutdownGrace and skip jobs.Stop when disabled Code review fixes for T16: - Pass cfg.Jobs.ShutdownGrace+5s to jobs.Stop call-site context (was hard-coded 30s, would mask configured longer grace). - Guard jobs.Stop block on cfg.Jobs.Enabled so disabled jobs don't spin up the no-op shutdown goroutine + timer. - Use clock.Real().Now() in deadLetterFn for consistency with the rest of the jobs wiring. --- internal/app/app.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/internal/app/app.go b/internal/app/app.go index 1b5bda0..32f4b63 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -311,7 +311,7 @@ func New(ctx context.Context, cfg *config.Config, dist embed.FS) (*App, error) { "job_id": job.ID.String(), "job_type": string(job.Type), }, - CreatedAt: time.Now().UTC(), + CreatedAt: clock.Real().Now().UTC(), }); derr != nil { log.Warn("dead_letter.dispatch_failed", "admin_id", a.ID, "err", derr.Error()) } @@ -412,9 +412,9 @@ func (a *App) Run(ctx context.Context) error { } // Stop jobs module first so no in-flight worker can dispatch new // notifications after we begin to drain the dispatcher. - if a.jobs != nil { + if a.jobs != nil && a.cfg.Jobs.Enabled { a.jobsCancel() - stopCtx, stopCancel := context.WithTimeout(context.Background(), 30*time.Second) + stopCtx, stopCancel := context.WithTimeout(context.Background(), a.cfg.Jobs.ShutdownGrace+5*time.Second) a.jobs.Stop(stopCtx) stopCancel() } @@ -427,9 +427,9 @@ func (a *App) Run(ctx context.Context) error { case err := <-errCh: drainCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() - if a.jobs != nil { + if a.jobs != nil && a.cfg.Jobs.Enabled { a.jobsCancel() - stopCtx, stopCancel := context.WithTimeout(context.Background(), 30*time.Second) + stopCtx, stopCancel := context.WithTimeout(context.Background(), a.cfg.Jobs.ShutdownGrace+5*time.Second) a.jobs.Stop(stopCtx) stopCancel() }