情景:
使用以下脚本完成部署到生产:
如何增强部署脚本以便执行以下操作?:
答案 0 :(得分:2)
以下脚本作为部署的一部分运行解决了问题:
import time
from celery.app.control import Control
from myapp.tasks import celery # my application's Celery app
if __name__ == "__main__":
control = Control(celery)
control.cancel_consumer("celery") # queue name, must probably be specified once per queue, but my app uses a single queue
inspect = control.inspect()
while True:
active = inspect.active()
running_jobs = []
for key, value in active.items():
running_jobs.extend(value)
if len(running_jobs) > 0:
print("{} jobs running: {}".format(len(running_jobs), ", ".join(job["name"] for job in running_jobs)))
time.sleep(10)
else:
print("No running jobs")
break