Celery-管理与监控
1. 监控和管理Workers
1.1 将celery实例放入shell
[root@node2 app]# celery -A tasks shell Python 3.6.5 (default, Oct 23 2019, 12:55:54) Type 'copyright', 'credits' or 'license' for more information IPython 7.8.0 -- An enhanced Interactive Python. Type '?' for help. In [1]: app Out[1]: <Celery tasks at 0x7ff7dddbdc18> In [2]: add.delay(1,2) Out[2]: <AsyncResult: c5cfd00f-8b11-4408-95e2-241f2f3d5521>
1.2 查看任务的结果
[root@node2 app]# celery -A tasks result c5cfd00f-8b11-4408-95e2-241f2f3d5521 3
1.3 从所有已配置的任务队列中清除消息
[root@node2 app]# celery -A tasks purge WARNING: This will remove all tasks from queue: celery. There is no undo for this operation! (to skip this prompt use the -f option) Are you sure you want to delete all tasks (yes/NO)? yes No messages purged from 1 queue
您还可以使用-Q选项指定要清除的队列:
$ celery -A proj purge -Q celery,foo,bar
并使用-X选项排除清除队列:
$ celery -A proj purge -X celery
1.4 列出活动的任务
celery -A tasks inspect active
1.5列出计划的ETA任务
celery -A tasks inspect scheduled
这些是设置了eta或countdown参数时由工作人员保留的任务 。
1.6 列出保留任务
celery -A tasks inspect reserved
这将列出工作者已经预取的所有任务,并且当前正在等待执行(不包括设置了ETA值的任务)。
1.7 列出已撤销任务的历史记录
$ celery -A tasks inspect revoked
1.8 列出注册的任务
celery -A tasks inspect registered
1.9 显示worker的统计信息
celery -A tasks inspect stats
1.10 查询任务信息
celery -A tasks inspect query_task task_id
1.11启用和禁用事件
celery -A tasks control enable_events/disable_events
2. Flower: Celery实时的Web监控
2.1 安装flower
pip install flower
2.2 启动Flower
celery -A tasks flower
可以添加--port参数指定监听端口,默认监听5555
或者通过指定Broker URL
$ celery flower --broker=amqp://guest:guest@localhost:5672// or $ celery flower --broker=redis://guest:guest@localhost:6379/0
3. celery events: Curses Monitor
celery -A tasks events
可以看件如下界面:
按j,k键可以选中task,查看任务结果