feat: resilient background job retry & monitoring (bounty #130)#936
Open
alexanderxfgl-bit wants to merge 1 commit intorohitdash08:mainfrom
Open
feat: resilient background job retry & monitoring (bounty #130)#936alexanderxfgl-bit wants to merge 1 commit intorohitdash08:mainfrom
alexanderxfgl-bit wants to merge 1 commit intorohitdash08:mainfrom
Conversation
…#130) Implements a production-ready background job queue with: - BackgroundJob model with status tracking (pending/running/succeeded/failed/retrying/dead) - Exponential backoff retry logic (30s base, 2x multiplier, 1hr cap) - Dead-letter queue for permanently failed jobs - REST API: POST/GET/DELETE /jobs, GET /jobs/stats, GET /jobs/dead, POST /jobs/<id>/retry - Scheduled job execution via scheduled_for field - PostgreSQL schema with optimized indexes for retry/pending queries - Comprehensive test suite (11 tests covering CRUD, retry, DLQ, validation) Closes rohitdash08#130
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bounty Claim: $250 — Issue #130
Implementation
Production-ready background job queue with retry, exponential backoff, and dead-letter queue support.
Backend Changes
Model (
app/models.py):JobStatusenum: pending → running → succeeded/failed → retrying → deadBackgroundJobmodel with: task_type, payload (JSON), status, attempts, max_attempts, last_error, result, next_retry_at, scheduled_forService (
app/services/jobs.py):enqueue_job()— create new jobs with optional schedulingmark_running/succeeded/failed()— lifecycle transitions_compute_backoff()— exponential backoff (30s base, 2x multiplier, 1hr cap)get_jobs_due_for_retry()/get_pending_jobs()— query helpers for workersmark_pending()— manual retry of dead/failed jobsRoutes (
app/routes/jobs.py):POST /jobs— enqueue job with validationGET /jobs— list with pagination + status/task_type filtersGET /jobs/<id>— get job detailsPOST /jobs/<id>/retry— manual retry of failed/dead jobsDELETE /jobs/<id>— remove jobGET /jobs/dead— dead-letter queue listingGET /jobs/stats— job statistics (total/pending/running/succeeded/failed/dead)Schema (
app/db/schema.sql):background_jobstable withjob_statusenum typeTests
11 tests covering:
Closes #130