Feature/celery notifications#221
Merged
nensii21 merged 2 commits intoJul 10, 2026
Merged
Conversation
…plication events Wire the existing create_notification service into real events (new follower, message received, application created/accepted/rejected) so notifications work end-to-end. Adds the missing notification schema and a NotificationService.notify helper that never notifies the actor and never breaks the primary action. Celery/Redis async delivery is intentionally left for a follow-up PR. Part of nensii21#161 (ECSoC 2026).
Move notification creation off the request thread onto a Celery worker backed by the already-configured Redis broker. Adds app.core.celery_app, an app.tasks package with send_notification_task (own DB session, retries, self-guard), and a NotificationService.enqueue helper with a synchronous fallback when the broker is down. Routers now enqueue instead of writing inline. Adds a worker service to docker-compose and a CELERY_TASK_ALWAYS_EAGER toggle for tests. Closes nensii21#161 (ECSoC 2026).
Owner
|
add screenshots and videos showing what changes have been made and also your CI jobs are failing please update it. |
Contributor
Author
|
@nensii21 sure i look into that |
Contributor
Author
|
@nensii21 as is a a backened feature so i cannot give u a screenshort for this |
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
Move notification creation off the request thread onto a Celery worker backed by the already-configured Redis broker. Adds the Celery app, a tasks package with
send_notification_task(own DB session, retries, self-guard), and aNotificationService.enqueuehelper with synchronous fallback when the broker is down. Routers now enqueue instead of writing inline.Related Issue
Closes #161 (ECSoC 2026)
Type of Change
Changes Made
backend/app/core/celery_app.py— Celery app with JSON serializer, timeouts, settings-driven eager flagbackend/app/core/config.py— addCELERY_TASK_ALWAYS_EAGERtogglebackend/app/tasks/__init__.py— exportssend_notification_taskbackend/app/tasks/notification_tasks.py— task with own DB session, 3 retries, reuses PR 1'snotify()enqueue()helper toNotificationService— builds JSON-safe payload, calls.delay(), falls back to syncnotify()on broker failurenotify(→enqueue(infollowers.py,messages.py,applications.pyworkerservice todocker-compose.yml(depends on postgres + redis)CELERY_TASK_ALWAYS_EAGERto.env.examplebackend/tests/test_notification_tasks.py— 3 tests (eager mode)Screenshots (if applicable)
N/A — backend-only change.
Testing
Additional testing notes: Tasks run eagerly (
CELERY_TASK_ALWAYS_EAGER=True) in tests — no broker needed. Three tests cover: task creates a notification in DB, task skips self-notification (returnsNone), and full router→enqueue→task integration viaTestClient. Verified viapyteston SQLite.Checklist
Additional Notes
PR 2 of 2. Depends on PR 1 (
feature/wire-notifications— auto-trigger notifications). The synchronousnotify()is deliberately kept as the single insert path reused by the task — no duplicated logic.Architecture:
POST /followers/{id} Celery worker (separate process)
send_notification_task db = SessionLocal()
.delay(payload) ───────► NotificationService.notify(db, ...)
return follow (instant) db.commit(); db.close()