12

有没有办法启动芹菜工人并在一个命令中击败?我想用 Fabric 将 celery 添加到我的自动部署过程中。

我目前正在运行:

celery -A prj worker -B

其次是

celery -A prj beat -l info -S django

但是,第一个命令会启动 worker,并且不允许运行下一个命令(开始节拍),因为会出现 worker 启动消息。

有没有办法避免出现启动消息?还是在一个命令中同时执行这两项操作?也许甚至有办法从我的 Django 配置开始这些?

谢谢!

4

2 回答 2

21

Celery 允许您在同一进程中运行 worker 和 beat(主要用于开发目的)。查看以下帮助celery worker

> celery worker -h

...

Embedded Beat Options:
  -B, --beat            Also run the celery beat periodic task scheduler. Please note that there must only be
                        one instance of this service. .. note:: -B is meant to be used for development
                        purposes. For production environment, you need to start celery beat separately.
  -s SCHEDULE_FILENAME, --schedule-filename SCHEDULE_FILENAME, --schedule SCHEDULE_FILENAME
                        Path to the schedule database if running with the -B option. Defaults to celerybeat-
                        schedule. The extension ".db" may be appended to the filename. Apply optimization
                        profile. Supported: default, fair
  --scheduler SCHEDULER
                        Scheduler class to use. Default is celery.beat.PersistentScheduler

因此,组合命令,包括您对django调度程序的使用,将如下所示:

celery -A prj worker --beat --scheduler django --loglevel=info
于 2017-03-29T03:21:24.017 回答
4
celery -A proj worker -l info -B
于 2021-01-28T07:02:16.223 回答