【问题标题】:Django with Celery and RabbitMQDjango 与 Celery 和 RabbitMQ
【发布时间】:2017-10-24 06:27:20
【问题描述】:

我正在开发一个应用程序,我必须使用 Celery 和 RabbitMQ 异步发送电子邮件。如何检查工作人员是否已发送电子邮件或失败?

【问题讨论】:

  • 是的,有可能

标签: django rabbitmq celery


【解决方案1】:

This SO explains what you are looking for.

基本上,以下是您需要做的。

task_id = uuid()
result = sendemail.apply_async((), task_id=task_id)
Now you know exactly what the task_id is and can now use it to get the AsyncResult:

# grab the AsyncResult 
result = celery.result.AsyncResult(task_id)

# print the task id
print result.task_id
09dad9cf-c9fa-4aee-933f-ff54dae39bdf

# print the AsyncResult's status
print result.status
SUCCESS

# print the result returned 
print result.result
'Email sent successfully'

【讨论】:

  • 谢谢你试试看