【问题标题】:Using chords in celery for multiple tasks在 celery 中使用和弦完成多项任务
【发布时间】:2020-12-26 23:31:27
【问题描述】:

我在注册任务时遇到问题。这是我的代码,请帮忙。

task.py

from celery_app import app
from celery import chord
from celery import signature

@app.task(bind=True)
def send_email(self):
    chorded_tasks = chord(get_expired_users.s(),notify.s()) #these tasks actually exist#
    chorded_tasks.get()
runthis.py

import celeryconfig
from celery import Celery
import os


celery = Celery()
celery.config_from_object("celeryconfig")
project_name = os.path.basename(os.getcwd())
celery.send_task(
    "tasks.send_email".format(project_name),
    kwargs={

    },
    args={

    },

上面的代码块是我正在运行的。它会运行良好,但实际上不会执行任务。我还有一个文件可以按计划运行它,而且效果也很好。我只是不明白为什么它不会运行实际任务

【问题讨论】:

  • 看起来"tasks.send_email".format(project_name) 缺少格式字符串占位符——可能是在尝试将代码匿名化为可共享示例时出错?我希望 project_name 会被丢弃。
  • 这是我的错误,需要项目名称而不是问题。对于那个很抱歉。我更担心我格式化和弦或和弦任务的方式
  • 如果你能帮我解决错误`AttributeError: type object 'chord' has no attribute 's'`

标签: python celery scheduled-tasks chord


【解决方案1】:

我相信您对args 参数使用了错误的类型。它应该是一个元组或一个列表。在您的示例中,您将字典作为 args 参数传递。这可能会导致您遇到的问题。考虑到您的任务没有参数,如下所示应该可以工作:celery.send_task("tasks.send_email".format(project_name), (), kwargs={})

【讨论】:

  • 这似乎不是问题。我现在收到一个错误Received unregistered task of type 'tasks.send_email'. The message has been ignored and discarded.
  • 我也收到了错误AttributeError: type object 'chord' has no attribute 's'
  • 该错误来自您未在此处显示的代码。您确实显示的代码不可能导致该 AttributeError。
猜你喜欢
  • 2019-02-22
  • 1970-01-01
  • 1970-01-01
  • 2018-02-11
  • 1970-01-01
  • 1970-01-01
  • 2013-08-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多