diff options
Diffstat (limited to 'python')
| -rw-r--r-- | python/client.py | 31 | ||||
| -rw-r--r-- | python/master.py | 33 |
2 files changed, 37 insertions, 27 deletions
diff --git a/python/client.py b/python/client.py index 1652ce4b..cb111dd9 100644 --- a/python/client.py +++ b/python/client.py @@ -2,17 +2,24 @@ import redis import tasks from pickle import loads, dumps import socket +import daemon +from daemon.pidlockfile import TimeoutPIDLockFile -hostname = socket.gethostname() -if hostname == 'debian': - q = redis.Redis(unix_socket_path='/var/run/redis/redis.sock') -elif hostname == 'gomez': - q = redis.Redis(host='debian') +def run(): + hostname = socket.gethostname() + if hostname == 'debian': + q = redis.Redis(unix_socket_path='/var/run/redis/redis.sock') + elif hostname == 'gomez': + q = redis.Redis(host='debian') -while True: - f, args = loads(q.blpop("tasks")[1]) - getattr(tasks, f)(*args) - if f == "build_portfolio": - q.rpush("tasks", dumps(("build_scenarios", args), protocol=2)) - if f == "build_scenarios": - q.rpush("tasks", dumps(("gen_scenarios", args[:-1]), protocol=2)) + while True: + f, args = loads(q.blpop("tasks")[1]) + getattr(tasks, f)(*args) + if f == "build_portfolio": + q.rpush("tasks", dumps(("build_scenarios", args), protocol=2)) + if f == "build_scenarios": + q.rpush("tasks", dumps(("generate_scenarios", args[:-1]), protocol=2)) + +if __name__=="__main__": + with daemon.DaemonContext(pidfile = TimeoutPIDLockFile('/var/run/client.pid',10)): + run() diff --git a/python/master.py b/python/master.py index 60bea7b4..c45c1cf2 100644 --- a/python/master.py +++ b/python/master.py @@ -3,21 +3,24 @@ from pickle import dumps import datetime import os import time +from common import root +import daemon +from daemon.pidlockfile import TimeoutPIDLockFile -if os.name =='nt': - root = "//WDsentinel/share/CorpCDOs" -elif os.name == 'posix': - root = '/home/share/CorpCDOs' +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()) -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) -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() |
