1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-04-14 08:17:13 +03:00

Make EDDN replay more robust in face of corrupted log

Fixes #211
This commit is contained in:
Jonathan Harris 2017-05-12 15:32:02 +01:00
parent da09b2392e
commit ecfe3ed357

36
eddn.py
View File

@ -115,21 +115,27 @@ class EDDN:
self.parent.status['text'] = '%s [%d]' % (_('Sending data to EDDN...').replace('...',''), len(self.replaylog))
self.parent.w.update_idletasks()
try:
self.send(*json.loads(self.replaylog[0], object_pairs_hook=OrderedDict))
self.replaylog.pop(0)
if not len(self.replaylog) % self.REPLAYFLUSH:
self.flush()
except EnvironmentError as e:
if __debug__: print_exc()
self.parent.status['text'] = unicode(e)
except requests.exceptions.RequestException as e:
if __debug__: print_exc()
self.parent.status['text'] = _("Error: Can't connect to EDDN")
return # stop sending
except Exception as e:
if __debug__: print_exc()
self.parent.status['text'] = unicode(e)
return # stop sending
cmdr, msg = json.loads(self.replaylog[0], object_pairs_hook=OrderedDict)
except:
# Couldn't decode - shouldn't happen!
if __debug__:
print self.replaylog[0]
print_exc()
self.replaylog.pop(0) # Discard and continue
else:
try:
self.send(cmdr, msg)
self.replaylog.pop(0)
if not len(self.replaylog) % self.REPLAYFLUSH:
self.flush()
except requests.exceptions.RequestException as e:
if __debug__: print_exc()
self.parent.status['text'] = _("Error: Can't connect to EDDN")
return # stop sending
except Exception as e:
if __debug__: print_exc()
self.parent.status['text'] = unicode(e)
return # stop sending
self.parent.w.after(self.REPLAYPERIOD, self.sendreplay)