diff options
Diffstat (limited to 'python/process_queue.py')
| -rw-r--r-- | python/process_queue.py | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/python/process_queue.py b/python/process_queue.py index 37fe0d99..107f0b80 100644 --- a/python/process_queue.py +++ b/python/process_queue.py @@ -82,11 +82,16 @@ def decode_dict(d): v.decode() if isinstance(v, bytes) else v for k, v in d.items()} def get_redis_queue(): - hostname = socket.gethostname() - if hostname == 'ziggy': - return redis.Redis(unix_socket_path='/run/redis/redis.sock') - else: - return redis.Redis(host='ziggy') + q = redis.Redis(unix_socket_path='/run/redis/redis.sock') + try: + q.ping() + except redis.ConnectionError: + try: + q = redis.Redis(os.environ['REDIS_HOST']) + except KeyError: + logging.error("Please set redis host in REDIS_HOST") + sys.exit(1) + return q def get_effective_date(d): return previous_twentieth(d + datetime.timedelta(days=1)) @@ -323,15 +328,21 @@ def upload_file(timestamp, queue_name='bond_trades'): ftp.cwd('incoming') filename = get_filename(timestamp, queue_name) cmd = 'STOR {0}'.format(filename) - with open(os.path.join('/home/serenitas/Daily', str(timestamp.date()), filename), 'rb') as fh: - ftp.storbinary(cmd, fh) + try: + with open(os.path.join(os.environ['DAILY_DIR'], str(timestamp.date()), filename), 'rb') as fh: + ftp.storbinary(cmd, fh) + except KeyError: + logging.error("Please set daily directory in DAILY_DIR") def write_buffer(buf, queue_name='bond_trades'): timestamp = pd.datetime.now() filename = get_filename(timestamp, queue_name) - with open(os.path.join('/home/serenitas/Daily', str(timestamp.date()), filename), 'wb') as fh: - fh.write(buf) - return timestamp + try: + with open(os.path.join(os.environ['DAILY_DIR'], str(timestamp.date()), filename), 'wb') as fh: + fh.write(buf) + return timestamp + except KeyError: + logging.error("Please set daily directory in DAILY_DIR") def email_subject(trade): return "[{0}] {1} {2} {3}".format(trade.asset_class, trade.action, |
