Celery Why Does Task Stay In Queue

那年仲夏 提交于 2019-12-06 14:00:51

问题


So I am using Celery with RabbitMQ. I have a RESTful API that registers a user. I am using remote Celery worker to send a registration email asynchronously so my API can return fast response.

from .tasks import send_registration_email

def register_user(user_data):
    # save user to the database etc

    send_registration_email.delay(user.id)

    return {'status': 'success'}

This works fine. Email is being sent in a non blocking asynchronous way (and can be retried if fails which is cool). The problem is when I look at RabbitMQ management console. I can see that the send_registration_email has created a random queue. Something like:

I can see that the task has been successfully executed. So why does the random queue stays in RabbitMQ forever? This is the task payload:

{"status": "SUCCESS", "traceback": null, "result": true, "task_id": "aad10877-3508-4179-a5fb-99f1bd0b8b2f", "children": []}

回答1:


This normal behaviour, if you have configured CELERY_RESULT_BACKEND in your settings. Please check here: Celery result backend description

You could disable result backend, or decrease each message life time.



来源:https://stackoverflow.com/questions/21077639/celery-why-does-task-stay-in-queue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!