Permalink
Browse files

very simple minded reconnect on fail

  • Loading branch information...
1 parent 30914f7 commit ea33caab453525f1196f4cb797678db69e1c3c54 @ArthurClune ArthurClune committed Jun 11, 2012
Showing with 15 additions and 7 deletions.
  1. +15 −7 cli/csv2file.py
View
@@ -4,7 +4,7 @@
import json
import logging
logging.basicConfig(level=logging.CRITICAL)
-
+from time import sleep
import hpfeeds
HOST = 'hpfeeds.honeycloud.net'
@@ -20,9 +20,6 @@ def main():
print >>sys.stderr, 'could not open output file for message log.'
return 1
- hpc = hpfeeds.new(HOST, PORT, IDENT, SECRET)
- print >>sys.stderr, 'connected to', hpc.brokername
-
def on_message(identifier, channel, payload):
try: decoded = json.loads(str(payload))
except: decoded = {'raw': payload}
@@ -39,9 +36,20 @@ def on_error(payload):
print >>sys.stderr, ' -> errormessage from server: {0}'.format(payload)
hpc.stop()
- hpc.subscribe(CHANNELS)
- hpc.run(on_message, on_error)
- hpc.close()
+ while True:
+ try:
+ hpc = hpfeeds.new(HOST, PORT, IDENT, SECRET)
+ print >>sys.stderr, 'connected to', hpc.brokername
+ hpc.subscribe(CHANNELS)
+ except hpfeeds.FeedException:
+ # failed to connect
+ sleep(20)
+ break
+ hpc.run(on_message, on_error)
+ hpc.close()
+ # if we get here, connection has error'd out
+ # just wait and try again
+ sleep(20)
return 0
if __name__ == '__main__':

0 comments on commit ea33caa

Please sign in to comment.