【问题标题】:Django Celery Result : Django-DB ttributeError: 'DisabledBackend'Django Celery 结果:Django-DB ttributeError: 'DisabledBackend'
【发布时间】:2017-07-02 14:56:05
【问题描述】:

我目前正在使用 Django DB 作为后端测试 Django Celery Results。

我已经按照这里的文档:http://docs.celeryproject.org/en/latest/django/first-steps-with-django.html#django-celery-results-using-the-django-orm-cache-as-a-result-backend

当我的 Django 视图调用 celery 任务时,它会正确添加到 Django DB 中,并且该任务由 Celery 工作人员执行。我还可以使用以下代码获取任务 ID:

def contact(request):
    if request.method == 'POST':
        form = ContactForm(request.POST)
        if form.is_valid():
            cd = form.cleaned_data
            res = mailer.delay(
                cd['subject'],
                cd['message'],
                cd.get('email', 'noreply@gmail.com'),
                ['seb.pouplin@gmail.com'])

            cel_taskid = res.task_id
            result = AsyncResult(cel_taskid)
            print(result.state)
            return HttpResponse(cel_taskid)

但是,每当我尝试获取任务状态、状态或 ready() 标志时,都会遇到以下异常:

AttributeError: 'DisabledBackend' 对象没有属性 '_get_task_meta_for'

使用 Django-DB 获取任务详细信息或任何其他方式检索它们是否有任何限制?

提前致谢

【问题讨论】:

  • 我能够使用来自 django_celery_results 的 TaskResult 模型访问 Celery 任务结果。

标签: django django-celery


【解决方案1】:

我能够使用 django_celery_results 中的 TaskResult 模型访问 Celery 任务结果。

最好的解决方案是在任务装饰器中添加(bind=True) 以访问任务对象属性。

【讨论】:

    猜你喜欢
    • 2019-06-09
    • 2022-11-25
    • 2021-02-25
    • 2011-10-14
    • 2012-08-27
    • 2019-11-15
    • 2012-01-15
    • 1970-01-01
    • 2015-05-20
    相关资源
    最近更新 更多