VintaSend Celery
Celery integration for VintaSend. It lets a NotificationService hand background sends to a
Celery worker.
This package does not implement a delivery adapter. It provides the queue service that enqueues a notification id and the task factories that register VintaSend's worker entrypoints as Celery tasks. The worker reloads the notification from your backend and delivers it through your own background adapter.
Installation
pip install vintasend vintasend-celery
How it fits together (VintaSend 2.0)
The background payload is just the notification id:
- Your adapter subclasses VintaSend's
BackgroundNotificationAdapterand puts its delivery insend(). NotificationService.send()sees the background adapter and hands the notification id to itsnotification_queue_service— theCeleryNotificationQueueServicefrom this package.- The queue service calls
.delay(notification_id)on the Celery task that runs VintaSend'ssend_notification. - The worker rebuilds a
NotificationService(fromNOTIFICATION_SERVICE_FACTORY, or one you pass in) and callsdelayed_send(notification_id), which reloads the notification, generates the context at delivery time, and calls your adapter'ssend().
Attachments work on this path without extra effort: the worker reads them from the backend.
Quick start
Register the worker task and wire the queue service against it:
from celery import Celery
from vintasend.services.notification_service import NotificationService
from vintasend.tasks.background_tasks import send_notification
from vintasend_celery.services.notification_queue_services.celery_queue_service import (
CeleryNotificationQueueService,
)
from vintasend_celery.tasks.background_tasks import send_notification_task_factory
celery_app = Celery("myapp", broker="redis://localhost:6379/0")
# Register VintaSend's id-only worker entrypoint as a Celery task.
send_notification_task = send_notification_task_factory(celery_app)
# The web process builds its service with this queue service.
queue_service = CeleryNotificationQueueService(send_notification_task=send_notification_task)
notification_service = NotificationService(
notification_adapters=[MyBackgroundEmailAdapter(...)], # subclasses BackgroundNotificationAdapter
notification_backend=MyBackend(...),
notification_queue_service=queue_service,
)
The worker needs to rebuild the service from scratch to get a live database session, so point
NOTIFICATION_SERVICE_FACTORY at a callable that returns a ready NotificationService:
# myapp/worker.py
def notification_service_factory():
return NotificationService(
notification_adapters=[MyBackgroundEmailAdapter(...)],
notification_backend=MyBackend(...),
)
export NOTIFICATION_SERVICE_FACTORY="myapp.worker.notification_service_factory"
The web and worker processes must read the same NOTIFICATION_BACKEND so the id resolves to the
same notification in both.
Periodic draining
To flush notifications whose send_after has arrived, register the periodic task and schedule it
on Celery beat:
from vintasend_celery.tasks.periodic_tasks import (
periodic_send_pending_notifications_task_factory,
)
periodic_task = periodic_send_pending_notifications_task_factory(celery_app)
AsyncIO hosts
If your NOTIFICATION_SERVICE_FACTORY returns an AsyncIONotificationService, use the AsyncIO
queue service and task factory instead:
from vintasend_celery.services.notification_queue_services.celery_queue_service import (
AsyncIOCeleryNotificationQueueService,
)
from vintasend_celery.tasks.background_tasks import async_send_notification_task_factory
async_task = async_send_notification_task_factory(celery_app)
queue_service = AsyncIOCeleryNotificationQueueService(send_notification_task=async_task)
Upgrading from 1.x
This release is a breaking change. See RELEASE_NOTES.md and the repository's
MIGRATION_TO_2.0.0.md for the full upgrade procedure, including draining or dual-registering
the Celery queue before deploying the 2.0 worker.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file vintasend_celery-2.0.0.tar.gz.
File metadata
- Download URL: vintasend_celery-2.0.0.tar.gz
- Upload date:
- Size: 9.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
poetry/2.0.0 CPython/3.12.2 Darwin/25.5.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4e1da3a9fef24af436abb93240e0f067fbf19de1167893ff205b13680a581950
|
|
| MD5 |
1740967a06284b41598ce9a9a0ed758e
|
|
| BLAKE2b-256 |
e98b3c4735d3c03177610c64e56f50290e3f3aee04612ad2161286370592dd6b
|
File details
Details for the file vintasend_celery-2.0.0-py3-none-any.whl.
File metadata
- Download URL: vintasend_celery-2.0.0-py3-none-any.whl
- Upload date:
- Size: 11.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
poetry/2.0.0 CPython/3.12.2 Darwin/25.5.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e64741407aecccfb341473af1a872eb01f3037d0e4d539afc70a80617d15fd07
|
|
| MD5 |
077c3e264384a74b7ef6df96e606ead0
|
|
| BLAKE2b-256 |
88265ec7619c24a9334264dcbf732e51d0dce8960824424f42f14abc70c0f19c
|