feat: resilient background job retry & monitoring (#130)#651
Open
DrGalio wants to merge 1 commit intorohitdash08:mainfrom
Open
feat: resilient background job retry & monitoring (#130)#651DrGalio wants to merge 1 commit intorohitdash08:mainfrom
DrGalio wants to merge 1 commit intorohitdash08:mainfrom
Conversation
Add a production-ready background job runner with retry logic, exponential backoff, dead-letter tracking, and monitoring endpoints. Changes: - New JobRunner service with configurable RetryPolicy and exponential backoff - BackgroundJob model tracking full job lifecycle (PENDING/RUNNING/COMPLETED/RETRYING/DEAD) - Fixed bug: reminder delivery now only marks sent=True on actual success - Failed deliveries auto-retry with exponential backoff (default 3 retries) - New monitoring endpoints: /jobs/stats, /jobs/dead, /jobs/retrying, /jobs/<id>/retry - Manual retry support for dead-lettered jobs - 11 new tests covering retry policy, execution, monitoring 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.
Summary
Implements resilient background job retry & monitoring — closes #130.
Problem
The current reminder system had a critical reliability issue:
run_duemarkedsent=Trueregardless of whethersend_reminderactually succeeded. Failed deliveries were silently lost with no retry mechanism.Solution
A production-ready background job runner with:
RetryPolicy(default: 3 retries, 5s base delay, 2x multiplier, 300s cap)BackgroundJobtracks attempts, errors, metadata through PENDING → RUNNING → COMPLETED / RETRYING / DEADGET /reminders/jobs/stats— aggregated counts by statusGET /reminders/jobs/dead— dead-lettered jobs for inspectionGET /reminders/jobs/retrying— jobs waiting for next retryPOST /reminders/jobs/<id>/retry— manually re-queue dead jobsChanges
services/job_runner.py(new)models.pyBackgroundJobmodel andJobStatusenumroutes/reminders.pydb/schema.sqlbackground_jobstable with indexestests/test_job_runner.py(new)Tests
All 11 new tests pass:
Acceptance Criteria (from issue)