Repository navigation
Add BackgroundTasks module with Celery + Redis queue and admin UI - #36
Merged
Merged
Conversation
Adds a new background_tasks module: Celery app with Redis broker/result backend, a TaskExecution table populated via Celery signals, an admin API + Inertia UI that lists executions with filters, and a retry action gated to failed/stuck rows. Other modules declare tasks by shipping a tasks.py — autodiscovery picks them up without framework changes. Infra: dedicated docker/worker.Dockerfile for worker + beat services, redis service added to docker-compose, .dockerignore, Makefile targets for local and containerized workers. https://claude.ai/code/session_013VMtYvyhYDHEDHGKWAQqPf
Code-quality and efficiency pass on the Celery module: - reuse framework's ENTRY_POINT_GROUP in celery_app - drop dead constants (CELERY_STATE_*, RUNNING_STATUSES) - drop dead 503 branch in service.retry (celery is always set by on_startup) - merge list+count into one window-function query - purge_old_executions now issues one DELETE instead of SELECT-then-IN - dispose the sync engine on shutdown so lifespan restarts don't leak pools - collapse six signal-handler try/except bodies via a shared _apply helper - extract shared retry flow (fetch + toast) and RetryConfirmDialog so Index.tsx and Detail.tsx stop duplicating the same ~20 lines each https://claude.ai/code/session_013VMtYvyhYDHEDHGKWAQqPf
…check)
- keep both background_tasks and file_storage in host/pyproject and root
ty/pytest paths
- rename background_tasks/tests/test_service.py to test_bg_service.py to
avoid pytest test-module collision with file_storage/tests/test_service.py
- regenerate packages/i18n/src/{keys,generated-resources}.ts with single
quotes (main's updated i18n_manifest generator) now that background_tasks
locales are in the registry
Full CI run: ruff, ty, biome, tsc, check_file_size, check_hardcoded_strings,
611 Python tests, 8 JS tests, make doctor all green.
https://claude.ai/code/session_013VMtYvyhYDHEDHGKWAQqPf
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
Introduces a complete BackgroundTasks module that integrates Celery + Redis for asynchronous task processing with a full-featured admin UI for monitoring and retrying failed/stuck tasks.
Key Changes
Core Infrastructure
celery_app.pywith automatic task discovery from installed modules via entry pointssignals.pyand_signal_support.pykeep a persistentTaskExecutiontable in sync with Celery task lifecycle (publish → prerun → success/failure/retry/revoked)sync_db.pymaintains a separate synchronous SQLAlchemy engine for signal handlers to avoid deadlocks in async contextsmodels.pydefines theTaskExecutiontable with full lifecycle tracking (status, timestamps, args/kwargs, results, tracebacks, retry chains)Background Jobs
tasks.pyimplements two scheduled tasks:sweep_stuck_tasks: Flips stalerunningtasks tostuckstatuspurge_old_executions: Deletes terminal task records older than retention periodscripts/run_worker.pyentry point for Celery worker and beat schedulerAdmin API & Views
endpoints/api_admin.pyprovides list, detail, and retry operations with permission checksendpoints/views.pyrenders server-side paginated task listingsservice.pyimplements business logic for listing, filtering, and retrying tasks with event emissionIndex.tsx,Detail.tsx) with search, filtering, pagination, and retry dialogsConfiguration & Contracts
settings.pyloads Celery broker/result backend URLs and tuning parameters from environmentconstants.pycentralizes all magic strings (table names, permissions, routes, task statuses)contracts/defines service interface, schemas, and events for other modules to depend onlocales/en.jsonand i18n key generation for UI stringsTesting & Deployment
test_signals.pyvalidates signal handlers with temporary SQLite;test_bg_service.pytests service logic;test_admin_api.pyend-to-end API testsworker.Dockerfilefor lean Celery worker/beat images; updateddocker-compose.ymlwith Redis service and worker containerbackground_tasks_task_executiontable with indexesNotable Implementation Details
retried_from_id, preserving execution historyrunning→success/failed/stuck/revoked); invalid transitions are logged but don't crashrunningtasks updateheartbeat_aton prerun; stale heartbeats triggerstuckstatus for manual retrybackground_tasks.view(read) andbackground_tasks.manage(retry) permissionshttps://claude.ai/code/session_013VMtYvyhYDHEDHGKWAQqPf