【问题标题】:Start celery beat from a python program without using command line arguments在不使用命令行参数的情况下从 python 程序启动 celery beat
【发布时间】:2019-12-30 02:30:52
【问题描述】:

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

@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

我需要创建一个类似的命令来启动 celery beat,我有以下方法

@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

--app 参数不适用于这种方法。有没有办法让这个命令以编程方式工作 celery -A proj beat 而无需从命令行传递?

【问题讨论】:

    标签: python celery celerybeat


    【解决方案1】:

    以编程方式启动 celery beat:

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

    或者:

    from celery.apps.beat import Beat
    
    b = Beat(app=your_celery_app, loglevel='debug')
    b.run()
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-04-22
      • 1970-01-01
      • 2012-08-14
      • 2020-02-27
      • 2013-04-25
      • 2020-08-16
      • 1970-01-01
      相关资源
      最近更新 更多