Python - queue.send()
Sends tasks to a queue.
from nitric.resources import queuefrom nitric.application import Nitricfrom nitric.api import Taskbatch_queue = queue('batch').allow('sending')payload = {}await batch_queue.send(payload)Nitric.run()
Parameters
- Name
tasks
- Required
- Required
- Type
- Task | Task[]
- Description
A task or an array of tasks to send to the queue.
Examples
Send a task to a queue
from nitric.resources import queuefrom nitric.application import Nitricfrom nitric.api import Taskbatch_queue = queue('batch').allow('sending')payload = {}await batch_queue.send(payload)Nitric.run()
Send multiple tasks to a queue
from nitric.resources import queuefrom nitric.application import Nitricfrom nitric.api import Taskbatch_queue = queue('batch').allow('sending')tasks = [{'type': 'Email','to': 'hello@example.com','subject': 'Notification','message': 'A notification from Nitric',},{'type': 'SMS','to': '+17200000000','message': 'A text message from Nitric',}]await batch_queue.send(tasks)Nitric.run()
Dealing with failures
In rare cases when sending tasks to a queue some tasks might fail to be sent. The response from send()
will include an array of any tasks that failed to send. You can process this array to retry or log the error.
failed = await batch_queue.send(tasks)for task in failed:print(task)
Last updated on Dec 24, 2024