changeset 157:b17ec3a6a112

browser side: in case of error, retry delay is doubled at each try
author Goffi <goffi@goffi.org>
date Sat, 05 Jan 2013 16:07:33 +0100
parents 46835a4e2551
children 58442ed28f2b
files libervia.py
diffstat 1 files changed, 10 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/libervia.py	Sat Jan 05 16:06:33 2013 +0100
+++ b/libervia.py	Sat Jan 05 16:07:33 2013 +0100
@@ -90,11 +90,19 @@
                         ])
 
 class BridgeSignals(LiberviaJsonProxy):
+    RETRY_BASE_DELAY = 1000
+
     def __init__(self, host):
         self.host = host
+        self.retry_delay = self.RETRY_BASE_DELAY 
         LiberviaJsonProxy.__init__(self, "/json_signal_api",
                         ["getSignals"])
     
+    def onRemoteResponse(self, response, request_info):
+        self.retry_delay = self.RETRY_BASE_DELAY 
+        LiberviaJsonProxy.onRemoteResponse(self, response, request_info)
+    
+    
     def onRemoteError(self, code, errobj, request_info):
         LiberviaJsonProxy.onRemoteError(self, code, errobj, request_info) 
         #we now try to reconnect
@@ -103,7 +111,8 @@
         else:
             def _timerCb():
                 self.host.bridge_signals.call('getSignals', self.host._getSignalsCB)
-            Timer(notify=_timerCb).schedule(5000) #we wait 5 s and try again
+            Timer(notify=_timerCb).schedule(self.retry_delay)
+            self.retry_delay *= 2
 
 class SatWebFrontend:
     def onModuleLoad(self):