comparison src/browser/sat_browser/json.py @ 846:c1907a460f6a

browser (json): changed rules for retry delay when connection with server is lost
author Goffi <goffi@goffi.org>
date Fri, 15 Jan 2016 15:42:37 +0100
parents a5b5178ef6b9
children fa7703642c0e
comparison
equal deleted inserted replaced
845:a5b5178ef6b9 846:c1907a460f6a
28 from pyjamas import JSONService 28 from pyjamas import JSONService
29 import time 29 import time
30 from sat_browser import main_panel 30 from sat_browser import main_panel
31 31
32 from sat_browser.constants import Const as C 32 from sat_browser.constants import Const as C
33 import random
33 34
34 35
35 class LiberviaMethodProxy(object): 36 class LiberviaMethodProxy(object):
36 """This class manage calling for one method""" 37 """This class manage calling for one method"""
37 38
246 else: 247 else:
247 remaining = int(self.retry_time - current) 248 remaining = int(self.retry_time - current)
248 msg_html = u"Connection with server lost. Retrying in <strong>{}</strong> s".format(remaining) 249 msg_html = u"Connection with server lost. Retrying in <strong>{}</strong> s".format(remaining)
249 self.retry_warning.showWarning("WARNING", msg_html, None) 250 self.retry_warning.showWarning("WARNING", msg_html, None)
250 251
251 retry_delay = 2**self.retry_nb 252 if self.retry_nb < 3:
253 retry_delay = 1
254 elif self.retry_nb < 10:
255 retry_delay = random.randint(1,10)
256 else:
257 retry_delay = random.randint(1,60)
252 self.retry_nb += 1 258 self.retry_nb += 1
253 log.warning(u"Lost connection, trying to reconnect in {} s".format(retry_delay)) 259 log.warning(u"Lost connection, trying to reconnect in {} s (try #{})".format(retry_delay, self.retry_nb))
254 self.retry_time = time.time() + retry_delay 260 self.retry_time = time.time() + retry_delay
255 self.retry_warning = main_panel.WarningPopup() 261 self.retry_warning = main_panel.WarningPopup()
256 self.retry_timer = Timer(notify=_timerCb) 262 self.retry_timer = Timer(notify=_timerCb)
257 self.retry_timer.scheduleRepeating(1000) 263 self.retry_timer.scheduleRepeating(1000)
258 _timerCb(None) 264 _timerCb(None)