Skip to content

Commit

Permalink
Update websocket-client and add ping every 15s
Browse files Browse the repository at this point in the history
  • Loading branch information
Fitblip committed Dec 20, 2019
1 parent 9b1937e commit 601fadc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions certstream/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,31 +27,31 @@ def __init__(self, message_callback, url, skip_heartbeats=True, on_open=None, on
on_error=self._on_error,
)

def _on_open(self, instance):
def _on_open(self):
certstream_logger.info("Connection established to CertStream! Listening for events...")
if self.on_open_handler:
self.on_open_handler(instance)
self.on_open_handler()

def _on_message(self, _, message):
def _on_message(self, message):
frame = json.loads(message)

if frame.get('message_type', None) == "heartbeat" and self.skip_heartbeats:
return

self.message_callback(frame, self._context)

def _on_error(self, instance, ex):
def _on_error(self, ex):
if type(ex) == KeyboardInterrupt:
raise
if self.on_error_handler:
self.on_error_handler(instance, ex)
self.on_error_handler(ex)
certstream_logger.error("Error connecting to CertStream - {} - Sleeping for a few seconds and trying again...".format(ex))

def listen_for_events(message_callback, url, skip_heartbeats=True, setup_logger=True, on_open=None, on_error=None, **kwargs):
try:
while True:
c = CertStreamClient(message_callback, url, skip_heartbeats=skip_heartbeats, on_open=on_open, on_error=on_error)
c.run_forever(**kwargs)
c.run_forever(ping_interval=15, **kwargs)
time.sleep(5)
except KeyboardInterrupt:
certstream_logger.info("Kill command received, exiting!!")
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
websocket-client==0.48.0
websocket-client>=0.56.0
termcolor

0 comments on commit 601fadc

Please sign in to comment.