Add a job-queue health check so stalled background jobs can't go unnoticed again

Aperta Adatta ai principianti
#7,291 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
72/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
rails, ruby

Direzione di ricerca

Inizia da app/controllers/health_controller.rb, accanto all'azione health esistente, e aggiungi l'azione jobs; la route va sotto resources :health in config/routes.rb. Conta solo le righe Delayed::Job scadute e non fallite (run_at <= now, failed_at nil) usando due query di aggregazione, e restituisci 503 quando il job scaduto più vecchio supera la soglia ENV (predefinita 3600). È completato quando spec/requests/health_spec.rb copre 200 vuoto, 200 recente, 503 obsoleto e un body senza dati di handler o argomenti.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Difficulty: Intermediate Good First Issue Help Wanted

Problem

From early 2022 until 2026-11-01, production background jobs (delayed_job) never ran: no worker dyno was on and nothing in Heroku Scheduler processed the queue. About 8,000 jobs piled up, mostly emails: followup notifications, supervisor reimbursement requests, and completed-reimbursement notices. Nobody noticed for 4.5 years, because nothing checks that jobs are actually being processed.

A Scheduler entry now runs rake jobs:workoff every 10 minutes. If it stops (removed by mistake, failing on boot, a rake-only bug like #7283), we'd be blind again.

Proposal

Add a cheap queue-health signal that an uptime monitor can poll.

  • New endpoint, e.g. GET /health/jobs.json, next to the existing /health (app/controllers/health_controller.rb, route in config/routes.rb under resources :health). It returns only aggregate numbers, never job payloads (handlers contain record IDs and arguments):
    {"queued": 3, "oldest_queued_age_seconds": 412, "failing": 0}
    
    • queued: Delayed::Job.where(failed_at: nil).count
    • oldest_queued_age_seconds: age of the oldest job that is due to run (run_at <= now, not failed), or null
    • failing: jobs with last_error set, or attempts > 0
  • Respond 503 when the oldest due job is older than a threshold (e.g. 1 hour; configurable via ENV, default 3600), so a simple HTTP uptime check can alert on it. Otherwise 200.
  • Request spec in spec/requests/health_spec.rb: 200 with an empty queue, 200 with a fresh job, 503 with a job older than the threshold, and no handler or argument data in the response body.
  • Keep it cheap: two indexed aggregate queries, no loading of job rows.
  • Document the endpoint in the wiki deploy checklist / README so a maintainer can point an uptime monitor at it. A maintainer will set up the actual monitor.

Notes

  • Jobs with a future run_at (retry backoff) shouldn't count as "stuck". Only count jobs that are due.
  • Don't require auth for the JSON, since it exposes only counts. If you'd rather gate it, follow the token pattern used by old_objects in the same controller.

Difficulty: beginner–intermediate. One controller action, one route, one request spec.

Lingua principale
Ruby
Stelle
382
Fork
547
Merge medio
2g 22h
PR unite (30g)
46

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di rubyforgood/casa

Tutte le issue di rubyforgood/casa

Issue simili

Altre issue su Ruby

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.