import redis from pickle import dumps import datetime import os import time from common import root import daemon from daemon.pidlockfile import TimeoutPIDLockFile def run(): dealsfile = os.path.join(root, "scripts", "deals_to_price.txt") q = redis.Redis(unix_socket_path='/var/run/redis/redis.sock') workdate = str(datetime.date.today()) while True: if os.path.exists(dealsfile): with open(dealsfile) as fh: for line in fh: dealname, reinvflag = line.rstrip().split("\t") q.rpush("tasks", dumps(("build_portfolio", [workdate, dealname, reinvflag]), protocol=2)) os.unlink(dealsfile) time.sleep(3) if __name__=="__main__": with daemon.DaemonContext(pidfile = TimeoutPIDLockFile('/var/run/master.pid',10)): run()