简体   繁体   English

在 celery 中使用和弦执行多项任务

[英]Using chords in celery for multiple tasks

I am having a problem getting my tasks to register.我在注册任务时遇到问题。 Here is my code, please help.这是我的代码,请帮忙。

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={

    },

the code block above is what I am running.上面的代码块是我正在运行的。 It will run fine but it wont actually do the tasks.它会运行良好,但实际上不会执行任务。 I also have a file that runs this on a schedule and that works fine as well.我还有一个按计划运行的文件,它也能正常工作。 I just don't understand why it wont run the actual tasks我只是不明白为什么它不会运行实际任务

I believe you are using wrong type for the args parameter.我相信您对args参数使用了错误的类型。 It should be a tuple or a list.它应该是一个元组或一个列表。 In your example you are passing a dictionary as args parameter.在您的示例中,您将字典作为 args 参数传递。 That could cause the problem you are having.这可能会导致您遇到的问题。 Considering that your task has no arguments something like the following should work: celery.send_task("tasks.send_email".format(project_name), (), kwargs={})考虑到您的任务没有参数,如下所示应该可以工作: celery.send_task("tasks.send_email".format(project_name), (), kwargs={})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM