系统相关
首页 > 系统相关> > circus 做为批处理的守护进程

circus 做为批处理的守护进程

作者:互联网

circus 是集成了zeromq,使用python编写的一个进程以及socket 管理工具,使用circus 的进程管理,我们可以用来进行批任务的
处理,同时又能保证任务的准确

项目使用docker+ docker-compose 运行

案例

项目结构

 
├── Dockerfile
├── README.md
├── circus.ini
├── docker-compose.yaml
├── entrypoint.sh
└── webapp
    ├── info.py
    ├── info2.py
    └── info3.py
 
info.py:
#!/usr/bin/env python
def main(args):
        print(1,"this is a demo")
if __name__ == '__main__':
    main("demo")
info2.py:
#!/usr/bin/env python
def main(args):
        print(2,"this is a demo")
if __name__ == '__main__':
    main("demo")
info3.py:
#!/usr/bin/env python
def main(args):
        print(3,"this is a demo")
if __name__ == '__main__':
    main("demo")
[circus]
statsd = True
httpd = True
httpd_host = 0.0.0.0
check_delay = 5
endpoint = tcp://0.0.0.0:5555
pubsub_endpoint = tcp://0.0.0.0:5556
[watcher:webapp]
cmd = python /app/webapp/info.py
numprocesses = 1
shell = True
[watcher:webapp2]
cmd = python /app/webapp/info2.py
numprocesses = 1
shell = True
[watcher:webapp3]
cmd = python /app/webapp/info3.py
numprocesses = 1
shell = True
 
FROM dalongrong/circus:2.7-slim-stretch
WORKDIR /app
COPY circus.ini /app/
COPY webapp/ /app/webapp/
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
ENTRYPOINT [ "/entrypoint.sh" ]
#!/bin/sh
circusd /app/circus.ini
version: "3"
services: 
  web:
    build: ./
    hostname: web
    ports: 
    - "9999:9999"
    - "8080:8080"
    - "5555:5555"

运行&&效果

docker-compose up -d 

 


统计监控

 

说明

以上只是一个简单的演示,实际上我们基于circus 的watch 特性,可以确保worker 任务的准确以及一致,使用circus
对于我们确保任务可靠是一种很不错的方案

参考资料

https://github.com/rongfengliang/circus-batch-worker-docker-compose
https://github.com/circus-tent/circus
https://circus.readthedocs.io/en/latest/for-ops/configuration/

标签:__,py,批处理,circus,python,webapp,main,守护
来源: https://www.cnblogs.com/rongfengliang/p/10999698.html