在不使用命令行参数的情况下从python程序启动celery beat

时间:2019-12-30 02:30:52

标签: python celery celerybeat

我已经实现了一个启动celery的python命令

__iter__

我需要创建一个类似的命令来启动芹菜节拍,我有以下方法

@click.command("tasks", help="run this command to start celery task queue")
def tasks():
    """
    Runs the celery task queue
    """
    from celery.bin import worker

    try:

        worker = worker.worker(app=app.config.get("task_app"))
        worker.run(app="my_app.task_queue", loglevel="info", uid=os.environ["uid"])
    except Exception as e:
        raise e

--app参数不适用于此方法。是否有一种方法可以使该命令以编程方式工作@click.command("beat", help="run this command to start beat") def beat(): try: p = app.config.get("task_app") # gets the current command = CeleryCommand() lst = ["celery", "beat"] command.execute_from_commandline(lst) except Exception as e: raise e 而无需从命令行传递过来?

1 个答案:

答案 0 :(得分:1)

要以编程方式开始芹菜拍打:

app.Beat(loglevel='debug').run()

或者:

from celery.apps.beat import Beat

b = Beat(app=your_celery_app, loglevel='debug')
b.run()

有关关键字参数,请参见celery.beat documentation

相关问题