Pythoncelery(v4.1.0)beat任务无法运行,参数为numb

2024-05-23 23:40:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我的目的是从MongoDB中提取任务配置,以启动beat任务导出(args)。但只得到一个错误:export() takes 0 positional arguments but 15 were given,下面是配置文件:

from celery.schedules import crontab
from exportUtils import MongodbUtils

broker_url = 'amqp://ops:123465@127.0.0.1:5672/tasks'
mongo_uri = "mongodb://task:task@localhost/task_config?authMechanism=SCRAM-SHA-1"
beat_schedule = {}

client = MongodbUtils(mongo_uri)
tasks = client.find("task_config", "cron_tasks", {"is_enabled": True})
client.close()
for task in tasks:
    crons = task["crontab_string"].split()
    schedule = crontab(hour=crons[0], minute=crons[1], day_of_week=crons[4], day_of_month=crons[2], month_of_year=crons[3])
    beat_schedule[task["task_name"]] = {
        'task': task["task_def"],
        'schedule': schedule,
        'args': (task["args"])
    }
print(beat_schedule)

任务导出():

@app.task
def export(paras):
    client = MySQLUtils(paras)
    cols, rows = client.execute_sql(paras["script"])
    export_to_xls(paras["output"], cols, rows)

我假设export()中的args是dict类型,并且beat_schedule在终端中打印出来时应该如下所示:

{'test_demo': 
    {'task': 'tasks.export', 
     'schedule': <crontab: * */1 * * * (m/h/d/dM/MY)>, 
     'args': {'receivers': 'lizhi@qq.com', 
     'content': 'Welcome', 
     'output': 'export.xls'
     .....
    }
 }}

我已将导出(第段)更改为导出(**第段),仍然不走运,有人请帮忙吗?如果需要任何进一步的信息,也请告诉我。Thx:)


Tags: offromimportclienttaskmongoargsexport