Skip to content

Commit aea06c5

Browse files
author
CUAUV
committed
Merge pull request #73 in SOF/subcode from auvlog to master
1 parent 499cb7f commit aea06c5

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

auvlog/daemon.py

+13-8
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
from auvlog import config
1414

15-
redis = redis.StrictRedis()
15+
redis_client = redis.StrictRedis()
1616

1717
socketS = nanomsg.Socket(nanomsg.SUB)
1818
socketS.set_string_option(nanomsg.SUB, nanomsg.SUB_SUBSCRIBE, '')
@@ -21,16 +21,21 @@
2121
socketP = nanomsg.Socket(nanomsg.PUB)
2222
socketP.bind("tcp://*:{0}".format(config.SERVER_PORT))
2323

24+
2425
def push_to_file(entry):
25-
try:
26-
f = open(os.path.join(os.environ['CUAUV_LOG'], 'current/auvlog.log'), 'ab')
27-
f.write(entry + b'\n')
28-
except IOError:
29-
print('Warning: Unable to write log entry to file.')
26+
try:
27+
f = open(os.path.join(os.environ['CUAUV_LOG'], 'current/auvlog.log'), 'ab')
28+
f.write(entry + b'\n')
29+
except IOError:
30+
print('Warning: Unable to write log entry to file.', flush=True)
31+
3032

3133
while True:
3234
res = socketS.recv()
33-
redis.lpush(config.KEY, res)
34-
redis.ltrim(config.KEY, 0, int(1e5))
35+
try:
36+
redis_client.lpush(config.KEY, res)
37+
redis_client.ltrim(config.KEY, 0, int(1e5))
38+
except redis.exceptions.ConnectionError:
39+
print('Warning: Unable to connect to redis instance', flush=True)
3540
push_to_file(res)
3641
socketP.send(res)

0 commit comments

Comments
 (0)