Skip to main content

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:

  1. Your adapter subclasses VintaSend's BackgroundNotificationAdapter and puts its delivery in send().
  2. NotificationService.send() sees the background adapter and hands the notification id to its notification_queue_service — the CeleryNotificationQueueService from this package.
  3. The queue service calls .delay(notification_id) on the Celery task that runs VintaSend's send_notification.
  4. The worker rebuilds a NotificationService (from NOTIFICATION_SERVICE_FACTORY, or one you pass in) and calls delayed_send(notification_id), which reloads the notification, generates the context at delivery time, and calls your adapter's send().

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

vintasend_celery-3.1.1.tar.gz (9.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

vintasend_celery-3.1.1-py3-none-any.whl (11.8 kB view details)

Uploaded Python 3

File details

Details for the file vintasend_celery-3.1.1.tar.gz.

File metadata

  • Download URL: vintasend_celery-3.1.1.tar.gz
  • Upload date:
  • Size: 9.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for vintasend_celery-3.1.1.tar.gz
Algorithm Hash digest
SHA256 1404360810e5f08eb1b5246f42b9ee2f8fd2c2897080d55f82a15e0d4640037b
MD5 970551a650598130b6b9ecce962615e6
BLAKE2b-256 9243db0bb5ea7c5eccdf920b81c09ff3b6a1c9fd32fe7cff361c943b5b2a02c8

See more details on using hashes here.

Provenance

The following attestation bundles were made for vintasend_celery-3.1.1.tar.gz:

Publisher: publish.yml on vintasoftware/vintasend-celery

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file vintasend_celery-3.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for vintasend_celery-3.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c258a528003373dad2aa38c9ecfe5bf32ae4fbbc4032e96321defb3f422a0d50
MD5 3dedac6a52ca1b1c0eda766d6420f7da
BLAKE2b-256 9deb6a248a5cc764773d585b5c7c346f8e98d03cbf59cdd1340c66439686f72a

See more details on using hashes here.

Provenance

The following attestation bundles were made for vintasend_celery-3.1.1-py3-none-any.whl:

Publisher: publish.yml on vintasoftware/vintasend-celery

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

3.1.1 This release

2 files

3.1.0

2 files

3.0.0

2 files

2.0.0

2 files

1.2.0

2 files

1.1.3

2 files

1.1.2

2 files

1.0.1

2 files

0.1.4

2 files

0.1.2

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page