Dispatching Jobs
Using the dispatch() Helper
from core.queue.queue_manager import dispatch
from app.jobs.send_notification_job import SendNotificationJob
# In your MQTT handler or anywhere in your code
async def handle_message(context):
# Create and configure the job
job = SendNotificationJob()
job.user_id = 123
job.message = "Your order has been shipped!"
# Dispatch to queue
await dispatch(job)Using the Queue Manager
Delayed Jobs
Bulk Dispatching
Dispatching from MQTT Handlers
Example 1: Dispatch from Controller
Example 2: Dispatch with Middleware
Example 3: Conditional Dispatching
Checking Queue Size
Queue Manager API Reference
push()
later()
bulk()
size()
Common Patterns
Pattern 1: Fan-out
Pattern 2: Delayed Chain
Pattern 3: Priority Queues
Pattern 4: Rate Limiting
Error Handling
Handle Dispatch Errors
Verify Job Data
Best Practices
1. Dispatch Early, Process Later
2. Don't Dispatch Too Much Data
3. Use Appropriate Delays
4. Choose the Right Queue
Next Steps
Last updated