Skip to content

Commit

Permalink
when query statistic failed, stop post the stat data
Browse files Browse the repository at this point in the history
  • Loading branch information
jiankai committed Jun 21, 2020
1 parent 417d8fe commit 9eeb32b
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions januscloud/sentinel/janus_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ def set_status(self, new_status):
return # ignore state change when maintaining
old_status = self.status
self.status = new_status

if old_status != new_status:
log.info('janus server({}) status changed to {}'.format(self.url, new_status))
for listener in self._listeners:
Expand All @@ -114,9 +115,10 @@ def set_stat(self, session_num, handle_num):
if stat_updated:
log.info('janus server({}) stat updated: session_num {}, handle_num {}'.format(
self.url, self.session_num, self.handle_num))
for listener in self._listeners:
if hasattr(listener, 'on_stat_updated') and callable(listener.on_stat_updated):
listener.on_stat_updated()
if session_num >= 0 or handle_num >= 0:
for listener in self._listeners:
if hasattr(listener, 'on_stat_updated') and callable(listener.on_stat_updated):
listener.on_stat_updated()

def register_listener(self, listener):
self._listeners.append(listener)
Expand Down Expand Up @@ -176,6 +178,7 @@ def query_stat(self):
self.set_stat(session_num=len(sessions), handle_num=len(handles))
except Exception as e:
log.warning('calculate stat of janus server({}) failed: {}'.format(self.admin_url, e))
self.set_stat(session_num=-1, handle_num=-1) # stop post statistic
if self._admin_ws_client:
try:
self._admin_ws_client.close()
Expand Down

0 comments on commit 9eeb32b

Please sign in to comment.