Skip to content

Commit fa6e0e1

Browse files
committed
ping the server to trigger reconnect on WS fail
1 parent 82106de commit fa6e0e1

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

rtmbot.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def dbg(debug_string):
1919

2020
class RtmBot(object):
2121
def __init__(self, token):
22+
self.last_ping = 0
2223
self.token = token
2324
self.bot_plugins = []
2425
self.slack_client = None
@@ -34,7 +35,15 @@ def start(self):
3435
self.input(reply)
3536
self.crons()
3637
self.output()
38+
self.autoping()
3739
time.sleep(.1)
40+
def autoping(self):
41+
#hardcode the interval to 3 seconds
42+
now = int(time.time())
43+
if now > self.last_ping + 3:
44+
print 'ping'
45+
self.slack_client.server.ping()
46+
self.last_ping = now
3847
def input(self, data):
3948
if "type" in data:
4049
function_name = "process_" + data["type"]

0 commit comments

Comments
 (0)