Management Commands¶
The module provides three management commands for processing, inspection, and demo data generation.
process_notifications¶
Processes pending email notifications and due newsletter tasks. Designed for cron-based deployments without Celery.
python manage.py process_notifications
What it does:
Finds all
EmailNotificationobjects withstatus='pending'andenqueued=True.Locks each one (using
select_for_update(skip_locked=True)), sets status tosending, and sends it.Finds all
NewsLetterTaskobjects withstatusin('pending', 'scheduled')andsend_datein the past.Locks each one, sets status to
sending, and sends the associated newsletter.Cleans up orphaned
AttachedFileobjects (object_id=0, older than 24 hours) and deletes their files.Reports the number of sent, failed, and cleaned items.
Cron example:
# Run every 5 minutes
*/5 * * * * cd /path/to/project && python manage.py process_notifications
Note
The command uses select_for_update(skip_locked=True) for safe concurrent execution.
Multiple instances can run simultaneously without processing the same notification twice.
inspect_notification¶
Displays the current async_notification system configuration: settings, registered contexts, model fields, and resolvers.
# Show all configuration
python manage.py inspect_notification
# Show detailed model fields for each context
python manage.py inspect_notification --fields
# Filter by a specific context code
python manage.py inspect_notification --context order_confirmation --fields
# Output in JSON format (for scripting)
python manage.py inspect_notification --json
Arguments:
--context CODE- Filter output to a specific context code.--fields- Show detailed model fields for each registered context.--json- Output in JSON format instead of human-readable text.
Example output:
=== Settings ===
ASYNC_NOTIFICATION_BACKEND: None
ASYNC_NOTIFICATION_MAX_PER_MAIL: 40
ASYNC_NOTIFICATION_MAX_RETRIES: 3
...
=== Registered Contexts ===
[order_confirmation]
Subject: Order #{{ order.id }} Confirmed
Models: {'order': 'myapp.Order', 'user': 'auth.User'}
Extra Variables: {'site_url': 'Full URL of the site'}
Depth: 2
Fields:
{{ order.id }} [integer] ID
{{ order.total }} [decimal] Total
{{ user.username }} [string] Username
{{ user.email }} [email] Email address
{{ site_url }} (custom) - Full URL of the site
=== Resolvers ===
@group.local -> DjangoGroupResolver
create_notification_demo¶
Generates demo data for all async_notification models. Useful for development and testing.
# Create demo data
python manage.py create_notification_demo
# Clear existing data first
python manage.py create_notification_demo --clear
# Associate with a specific user
python manage.py create_notification_demo --clear --user admin
Arguments:
--clear- Delete all existing async_notification data before creating demo data.--user USERNAME- Username to associate with notifications and newsletters.
Created data:
3 Email Templates:
welcome,password-reset,order-confirmation4 Email Notifications: One for each status (
pending,sending,sent,failed)2 Newsletter Templates:
monthly-digest,product-announcement2 Newsletters: One per template with sample recipients
8 Newsletter Tasks: 4 statuses per newsletter (
pending,scheduled,sent,failed)
Note
The createdemo command in the demo app automatically calls create_notification_demo --clear
as part of the full demo data setup.