Improved stream reconnection

This commit is contained in:
Manuel Cortez 2015-10-14 17:30:41 -05:00
parent 0f56d8cdd4
commit 792655e299
5 changed files with 17 additions and 13 deletions

View File

@ -125,7 +125,7 @@ class Controller(object):
log.debug("Binding other application events...")
pub.subscribe(self.logout_account, "logout")
pub.subscribe(self.login_account, "login")
pub.subscribe(self.manage_stream_errors, "streamError")
pub.subscribe(self.manage_stream_errors, "stream-error")
pub.subscribe(self.create_new_buffer, "create-new-buffer")
pub.subscribe(self.restart_streams, "restart-streams")
pub.subscribe(self.execute_action, "execute-action")
@ -1245,8 +1245,12 @@ class Controller(object):
self.set_buffer_positions(i)
def manage_stream_errors(self, session):
log.debug(" Restarting %s session streams. It will be destroyed" % (session,))
log.error(" Restarting %s session streams. It will be destroyed" % (session,))
s = session_.sessions[session]
del s.main_stream
del s.timelinesStream
s.counter = 0
s.reconnection_function_active = False
for i in self.buffers:
if i.invisible == True and i.session.session_id == s.session_id and i.type != "people":
i.start_stream()

View File

@ -27,7 +27,9 @@ def stream_threaded(func, *args, **kwargs):
try:
func(**k)
except:
pub.sendMessage("streamError", session=a[0])
log.error("Error in stream with args: %r" % (a,))
pub.sendMessage("stream-error", session=a[0])
thread = threading.Thread(target=new_func, args=args, kwargs=kwargs)
thread.daemon = True
thread.start()

View File

@ -21,12 +21,12 @@ class timelinesStreamer(TwythonStreamer):
self.lists = self.session.lists
def on_error(self, status_code, data):
log.debug("%s: %s" % (status_code, data))
pub.sendMessage("stream-error")
log.error("%s: %s" % (status_code, data))
pub.sendMessage("stream-error", session=self.session.session_id)
def on_timeout(self, *args, **kwargs):
log.debug("Twitter timeout Error")
pub.sendMessage("stream-error")
log.error("Twitter timeout Error")
pub.sendMessage("stream-error", session=self.session.session_id)
def check_tls(self, data):
for i in self.session.settings["other_buffers"]["timelines"]:

View File

@ -22,12 +22,12 @@ class streamer(TwythonStreamer):
# self.blocked_users = []
def on_timeout(self, *args, **kwargs):
log.debug("Twitter timeout Error")
pub.sendMessage("stream-error")
log.error("Twitter timeout Error")
pub.sendMessage("stream-error", session=self.session.session_id)
def on_error(self, status_code, data):
log.debug("Error %s: %s" % (status_code, data))
pub.sendMessage("stream-error")
log.error("Error %s: %s" % (status_code, data))
pub.sendMessage("stream-error", session=self.session.session_id)
def get_user(self):
return self.session.db["user_name"]

View File

@ -53,5 +53,3 @@ class twitter(object):
settings["twitter"]["user_secret"] = user_secret
settings.write()
def __init__(self):
log.error(certs.where())