#!/usr/bin/env python # -*- coding: utf-8 -*- # 用于批量处理转换 运行多个转换容器 # nohup python /data/dm/container/web/master.py 2>/dev/null & import time import subprocess import os import pprint timeSleep = 120 def redis(): import redis host = '0.0.0.0' port = 6379 password = 'dm_redis_123' pool = redis.ConnectionPool(host=host, password=password, port=int(port)) return redis.Redis(connection_pool=pool) def command(file): #return 'dm call office-convert_call id=' + file return 'docker run -d -it --entrypoint python --rm -v /data/dm/container/share:/share -v /etc/hosts:/etc/hosts.main --env HOSTIP="172.30.0.6" --net=dm -v /data/dm/container/web:/www -v /data/dm/container/web/convert/static:/usr/local/convert/front/static -v /data/dm/container/web/convert/files:/usr/local/convert/runtime/files registry.cn-hangzhou.aliyuncs.com/shemic/convert /usr/local/convert/convert.py -f ' + file def popen(command, bg=False): string = command if bg == True: command = command + ' &' process = os.popen(command) output = process.read() process.close() return output # 文档转换 def convert(): check = 'ps -ef | grep master_cron.py | grep -v grep | wc -l' value = int(popen(check)) if value > 1: return 1; r = redis() c = 'office_file' i = 0 # r.ltrim("list2", 0, 1) # n = r.llen(c) while 1: file = r.lpop(c) if file: g = command(file) popen(g, False) i = i+1 if i >= 10: time.sleep(timeSleep) i = 0 def handle(): convert() handle()