feat: resilient background job retry & monitoring#401
Open
TallowX92 wants to merge 1 commit intorohitdash08:mainfrom
Open
feat: resilient background job retry & monitoring#401TallowX92 wants to merge 1 commit intorohitdash08:mainfrom
TallowX92 wants to merge 1 commit intorohitdash08:mainfrom
Conversation
Implements production-grade background job infrastructure for async reminder dispatch with exponential-backoff retry and a monitoring API. Scheduler: - APScheduler (BackgroundScheduler) initialized in create_app(), skipped in TESTING mode to avoid side effects in tests - process_due_reminders() runs every 60 seconds via interval trigger - Graceful shutdown registered via atexit Retry logic: - Failed deliveries are retried up to MAX_RETRIES (3) attempts - Exponential backoff: 5min -> 15min -> 45min between attempts - Reminders exceeding MAX_RETRIES are marked failed=True (no further attempts) - retry_count, last_error, next_retry_at, failed columns added to Reminder model - Schema compat ALTERs added for existing PostgreSQL deployments Monitoring endpoints (JWT-protected): - GET /jobs/status — scheduler health + registered job list - GET /jobs/reminders/stats — sent/pending/retrying/failed counts - POST /jobs/reminders/run — manual trigger for ops/debugging Tests (17 tests, 12 pass without Redis, 5 require Redis for auth): - Backoff delta unit tests - process_due_reminders: success, retry, backoff window, max retries, skip guards - Endpoint auth, stats, manual trigger
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.
/claim #130
Demo
demo2026-03-14.19-10-07.mp4
Scheduler started, job firing every 60 seconds, executing successfully with next run scheduled.
Summary
Production-grade background job infrastructure for async reminder dispatch with exponential-backoff retry and a live monitoring API.
What's included
Scheduler —
app/services/scheduler.pyBackgroundSchedulerwithMemoryJobStoreprocess_due_reminders()every 60 secondsfailed=Trueafter 3 retries, captureslast_errorFLASK_ENV=testing)New fields on
Remindermodelretry_countlast_errornext_retry_atfailedMonitoring endpoints —
GET/POST /jobs/jobs/status/jobs/reminders/stats/jobs/reminders/runTests —
tests/test_jobs.py(17 tests)