Skip to content

Commit

Permalink
Error handling on MS websockets (the 'meh just give up' model)
Browse files Browse the repository at this point in the history
  • Loading branch information
Undo1 committed Jun 13, 2016
1 parent fe4e6a3 commit 59ea098
Showing 1 changed file with 25 additions and 22 deletions.
47 changes: 25 additions & 22 deletions metasmoke.py
Expand Up @@ -13,29 +13,32 @@
class Metasmoke:
@classmethod
def init_websocket(self):
GlobalVars.metasmoke_ws = websocket.create_connection(GlobalVars.metasmoke_ws_host, origin=GlobalVars.metasmoke_host)
GlobalVars.metasmoke_ws.send(json.dumps({"command": "subscribe", "identifier": "{\"channel\":\"SmokeDetectorChannel\",\"key\":\"" + GlobalVars.metasmoke_key + "\"}"}))

while True:
try:
a = GlobalVars.metasmoke_ws.recv()
print(a)
data = json.loads(a)

if "message" in data:
message = data['message']

if isinstance(message, Iterable) and "message" in message:
GlobalVars.charcoal_hq.send_message("{ [metasmoke](https://github.com/Charcoal-SE/metasmoke) } " + message['message'])
except Exception, e:
GlobalVars.metasmoke_ws = websocket.create_connection(GlobalVars.metasmoke_ws_host, origin=GlobalVars.metasmoke_host)
GlobalVars.metasmoke_ws.send(json.dumps({"command": "subscribe", "identifier": "{\"channel\":\"SmokeDetectorChannel\"}"}))
print e
try:
GlobalVars.metasmoke_ws = websocket.create_connection(GlobalVars.metasmoke_ws_host, origin=GlobalVars.metasmoke_host)
GlobalVars.metasmoke_ws.send(json.dumps({"command": "subscribe", "identifier": "{\"channel\":\"SmokeDetectorChannel\",\"key\":\"" + GlobalVars.metasmoke_key + "\"}"}))

while True:
try:
exc_info = sys.exc_info()
traceback.print_exception(*exc_info)
except:
print "meh"
a = GlobalVars.metasmoke_ws.recv()
print(a)
data = json.loads(a)

if "message" in data:
message = data['message']

if isinstance(message, Iterable) and "message" in message:
GlobalVars.charcoal_hq.send_message("{ [metasmoke](https://github.com/Charcoal-SE/metasmoke) } " + message['message'])
except Exception, e:
GlobalVars.metasmoke_ws = websocket.create_connection(GlobalVars.metasmoke_ws_host, origin=GlobalVars.metasmoke_host)
GlobalVars.metasmoke_ws.send(json.dumps({"command": "subscribe", "identifier": "{\"channel\":\"SmokeDetectorChannel\"}"}))
print e
try:
exc_info = sys.exc_info()
traceback.print_exception(*exc_info)
except:
print "meh"
except:
print "Couldn't bind to MS websocket"

@classmethod
def send_stats_on_post(self, title, link, reasons, body, username, user_link, why, owner_rep, post_score, up_vote_count, down_vote_count):
Expand Down

0 comments on commit 59ea098

Please sign in to comment.