Mercurial > libervia-web
comparison libervia/server/server.py @ 1367:ce5cfe004d4e
server: new `--bridge-retries` option:
If bridge connection fails, it will be retried for the specified number of time (default
to 10) before giving up. Each try is spaced by 1 second.
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 20 Nov 2020 18:02:43 +0100 |
parents | 10517a8698ca |
children | 9624c2a89a92 |
comparison
equal
deleted
inserted
replaced
1366:f61e95438050 | 1367:ce5cfe004d4e |
---|---|
832 self.sessions = {} # key = session value = user | 832 self.sessions = {} # key = session value = user |
833 self.prof_connected = set() # Profiles connected | 833 self.prof_connected = set() # Profiles connected |
834 self.ns_map = {} # map of short name to namespaces | 834 self.ns_map = {} # map of short name to namespaces |
835 | 835 |
836 ## bridge ## | 836 ## bridge ## |
837 self._bridge_retry = self.options['bridge-retries'] | |
837 self.bridge = Bridge() | 838 self.bridge = Bridge() |
838 self.bridge.bridgeConnect(callback=self._bridgeCb, errback=self._bridgeEb) | 839 self.bridge.bridgeConnect(callback=self._bridgeCb, errback=self._bridgeEb) |
839 | 840 |
840 @property | 841 @property |
841 def roots(self): | 842 def roots(self): |
1205 ) | 1206 ) |
1206 self.site = server.Site(wrapped) | 1207 self.site = server.Site(wrapped) |
1207 self.site.sessionFactory = LiberviaSession | 1208 self.site.sessionFactory = LiberviaSession |
1208 | 1209 |
1209 def _bridgeCb(self): | 1210 def _bridgeCb(self): |
1211 del self._bridge_retry | |
1210 self.bridge.getReady( | 1212 self.bridge.getReady( |
1211 lambda: self.initialised.callback(None), | 1213 lambda: self.initialised.callback(None), |
1212 lambda failure: self.initialised.errback(Exception(failure)), | 1214 lambda failure: self.initialised.errback(Exception(failure)), |
1213 ) | 1215 ) |
1214 self.initialised.addCallback(lambda __: defer.ensureDeferred(self.backendReady())) | 1216 self.initialised.addCallback(lambda __: defer.ensureDeferred(self.backendReady())) |
1215 | 1217 |
1216 def _bridgeEb(self, failure_): | 1218 def _bridgeEb(self, failure_): |
1217 if isinstance(failure_, BridgeExceptionNoService): | 1219 if isinstance(failure_, BridgeExceptionNoService): |
1220 if self._bridge_retry: | |
1221 if self._bridge_retry < 0: | |
1222 print(_("Can't connect to bridge, will retry indefinitely. " | |
1223 "Next try in 1s.")) | |
1224 else: | |
1225 self._bridge_retry -= 1 | |
1226 print( | |
1227 _( | |
1228 "Can't connect to bridge, will retry in 1 s ({retries_left} " | |
1229 "trie(s) left)." | |
1230 ).format(retries_left=self._bridge_retry) | |
1231 ) | |
1232 time.sleep(1) | |
1233 self.bridge.bridgeConnect(callback=self._bridgeCb, errback=self._bridgeEb) | |
1234 return | |
1235 | |
1218 print("Can't connect to SàT backend, are you sure it's launched ?") | 1236 print("Can't connect to SàT backend, are you sure it's launched ?") |
1219 else: | 1237 else: |
1220 log.error("Can't connect to bridge: {}".format(failure)) | 1238 log.error("Can't connect to bridge: {}".format(failure)) |
1221 sys.exit(1) | 1239 sys.exit(1) |
1222 | 1240 |