tornado 消费队列并配合 superviosr 优雅重启

superviosr.conf

[group:tornadoes] programs=ana-8000,ana-8001,ana-8002,ana-8003[program:ana-8000] directory = /root/precedents_auto_clean command = python3 run.py autorestart = true restart=true[program:ana-8001] directory = /root/precedents_auto_clean1 command = python3 run.py autorestart = true restart=true[program:ana-8002] directory = /root/precedents_auto_clean2 command = python3 run.py autorestart = true restart=true[program:ana-8003] directory = /root/precedents_auto_clean3 command = python3 run.py autorestart = true restart=true

消费队列 具体参考 pika python rabbitmq 优先级队列
http_client = tornado.httpclient.HTTPClient() try: time_out = 100 #port在各个项目中配置好 url = "http://127.0.0.1:{}/clean?id={}".format(port, id) req = httpclient.HTTPRequest(url, request_timeout=time_out) http_client.fetch(req)except httpclient.HTTPError as e: if e.message == "Internal Server Error" or e.message == "Timeout": # 杀掉当前的port进程 command = '''kill -9 $(netstat -nlp | grep :''' + str( port) + ''' | awk '{print $7}' | awk -F"/" '{ print $1 }')''' os.system(command) print("杀死" + e.message) # 这里sleep 5s 是为了等待 supervisor autorestart time.sleep(5)http_client.close()

自启动脚本 参考 screen + rc.local 实现开机自启动多个窗口命令
启动 tornado 的部分
/usr/bin/supervisord -c /etc/supervisord.conf

【tornado 消费队列并配合 superviosr 优雅重启】启动消费队列
screen_name="c1" screen -dmS $screen_name cmd1="python3 /root/precedents_auto_clean/cron_receive.py"; screen -x -S $screen_name -p 0 -X stuff "$cmd1" screen -x -S $screen_name -p 0 -X stuff '\n'

    推荐阅读