Skip to content

Feature/celery notifications#221

Merged
nensii21 merged 2 commits into
nensii21:mainfrom
GitGuru-sudo:feature/celery-notifications
Jul 10, 2026
Merged

Feature/celery notifications#221
nensii21 merged 2 commits into
nensii21:mainfrom
GitGuru-sudo:feature/celery-notifications

Conversation

@GitGuru-sudo

Copy link
Copy Markdown
Contributor

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 a NotificationService.enqueue helper with synchronous fallback when the broker is down. Routers now enqueue instead of writing inline.


Related Issue

Closes #161 (ECSoC 2026)


Type of Change

  • Bug fix
  • New feature
  • Documentation update
  • Performance improvement
  • Refactoring
  • UI/UX enhancement
  • Tests
  • Other

Changes Made

  • Create backend/app/core/celery_app.py — Celery app with JSON serializer, timeouts, settings-driven eager flag
  • Edit backend/app/core/config.py — add CELERY_TASK_ALWAYS_EAGER toggle
  • Create backend/app/tasks/__init__.py — exports send_notification_task
  • Create backend/app/tasks/notification_tasks.py — task with own DB session, 3 retries, reuses PR 1's notify()
  • Add enqueue() helper to NotificationService — builds JSON-safe payload, calls .delay(), falls back to sync notify() on broker failure
  • Switch all PR 1 call sites from notify(enqueue( in followers.py, messages.py, applications.py
  • Add worker service to docker-compose.yml (depends on postgres + redis)
  • Add CELERY_TASK_ALWAYS_EAGER to .env.example
  • Create backend/tests/test_notification_tasks.py — 3 tests (eager mode)

Screenshots (if applicable)

N/A — backend-only change.


Testing

  • Tested locally
  • Existing tests pass
  • Added new tests
  • UI verified
  • Cross-browser tested (if applicable)

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 (returns None), and full router→enqueue→task integration via TestClient. Verified via pytest on SQLite.


Checklist

  • My code follows the project's coding standards.
  • I have tested my changes locally.
  • I have updated the documentation where necessary.
  • My changes do not introduce new warnings or errors.
  • I have reviewed my own code.
  • This pull request focuses on a single feature or fix.
  • I have linked the related issue.

Additional Notes

PR 2 of 2. Depends on PR 1 (feature/wire-notifications — auto-trigger notifications). The synchronous notify() 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()

…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).
@nensii21

nensii21 commented Jul 9, 2026

Copy link
Copy Markdown
Owner

add screenshots and videos showing what changes have been made and also your CI jobs are failing please update it.

@GitGuru-sudo

GitGuru-sudo commented Jul 9, 2026

Copy link
Copy Markdown
Contributor Author

@nensii21 sure i look into that

@GitGuru-sudo

Copy link
Copy Markdown
Contributor Author

@nensii21 as is a a backened feature so i cannot give u a screenshort for this

@nensii21 nensii21 merged commit 1efef24 into nensii21:main Jul 10, 2026
7 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Notifications are never triggered automatically + Celery/Redis are declared but unused

2 participants