模块和包.深入Celery之节点管理/任务调度/任务追踪

本文介绍Celery的任务管理命令,包括启动、关闭、重启节点的方法,并解释了常用参数的意义。此外还涉及任务调度与跟踪的相关操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

任务管理:

wKioL1huTiCx0wz9AABiY2tFjhs429.png

说明: 如上为运行任务后的标准输出,transport为消息代理,concurrency为默认进程池进程数,当所有子进程处于忙碌状态时必须等待空闲子进程处理,如果是IO密集型可尝试使用Eventlet/Gevent协程,具体可参考http://docs.jinkan.org/docs/celery/userguide/concurrency/index.html#concurrency,result为结果存储,queue为所有的队列以及交换机信息列表

参数含义
%p节点全名,如foo@bar.example.com
%n只包含主机名,如foo
%h包含域名的主机名,如bar.example.com
%d只包含域名,如example.com
%iPrefork类型的进程索引,主进程为0,根据-n指定的名称生成对应的从1开始累加的名称,常用于用于为每个子进程创建唯一的日志文件
%IPrefork类型的进程索引,主进程空,根据-n指定的名称生成对应的从1开始累加的名称,常用于用于为每个子进程创建唯一的日志文件

# 启动节点

celery multi start notify -A work.app -c 4 -l info --pidfile=notify.pid --logfile=notify.log

# 关闭节点

celery multi stop  notify -A work.app -c 4 -l info --pidfile=notify.pid --logfile=notify.log

celery multi stopwait  notify -A work.app -c 4 -l info --pidfile=notify.pid --logfile=notify.log

celery multi kill  notify -A work.app -c 4 -l info --pidfile=notify.pid --logfile=notify.log

# 重启节点

celery multi restart notify -A work.app -c 4 -l info --pidfile=notify.pid --logfile=notify.log

# 查看节点

celery multi names notify -A work.app -c 4 -l info --pidfile=notify.pid --logfile=notify.log

celery multi show notify -A work.app -c 4 -l info --pidfile=notify.pid --logfile=notify.log

说明: Celery提供了一个multi子名称,可以很方便的管理Celery应用的启动(notify表示应用的唯一标识,-A表示应用的入口文件,-c表示默认工作进程下将启动的子进程数,--pidfile表示进程文件,--logfile表示日志文件)/关闭(stop表示异步停止应用,stopwait表示同步等待停止应用,kill表示终止应用,但需要注意的是必须指定--pidfile和--logfile)/重启(restart表示重启应用,但需要注意的是默认multi并不记忆之前启动参数,所以需要和启动参数一样)

扩展: 如果想要跟踪不同子进程的日志可直接在--pidfile和--logfile中使用上面的格式化参数,如celery multi start notify -A work.app -c 4 -l info --pidfile=notify%I.pid --logfile=notify%I.log,则会在当前运行目录下生成不同进程的进程ID以及日志文件,但是当你关闭和重启的时候就不那么方便了~

 

任务调度:

celery beat --help

 

任务跟踪:

celery result --help

celery -A work.app inspect --help

 

在线控制:

celery amqp --help

celery -A work.app control --help

 

在线节点:

celery -A work.app status

 

原文转自: 乐搏学院http://www.learnbo.com/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值