mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-04-17 17:42:20 +03:00
Use StationServices to determine whether to retry for shipyard data
This commit is contained in:
parent
2f523487dc
commit
93adfff746
14
EDMC.py
14
EDMC.py
@ -198,12 +198,20 @@ try:
|
|||||||
else:
|
else:
|
||||||
sys.stderr.write("Station doesn't supply outfitting\n")
|
sys.stderr.write("Station doesn't supply outfitting\n")
|
||||||
|
|
||||||
|
if (args.s or args.n) and not args.j and not data['lastStarport'].get('ships') and monitor.stationservices and 'Shipyard' in monitor.stationservices:
|
||||||
|
# Retry for shipyard
|
||||||
|
sleep(SERVER_RETRY)
|
||||||
|
data2 = session.query()
|
||||||
|
if (data2['commander'].get('docked') and # might have undocked while we were waiting for retry in which case station data is unreliable
|
||||||
|
data2['lastSystem']['name'] == monitor.system and
|
||||||
|
data2['lastStarport']['name'] == monitor.station):
|
||||||
|
data = data2
|
||||||
|
|
||||||
if args.s:
|
if args.s:
|
||||||
if not data['lastStarport'].get('ships') and not args.j:
|
|
||||||
sleep(SERVER_RETRY)
|
|
||||||
data = session.query()
|
|
||||||
if data['lastStarport'].get('ships'):
|
if data['lastStarport'].get('ships'):
|
||||||
shipyard.export(data, args.s)
|
shipyard.export(data, args.s)
|
||||||
|
elif not args.j and monitor.stationservices and 'Shipyard' in monitor.stationservices:
|
||||||
|
sys.stderr.write("Failed to get shipyard data\n")
|
||||||
else:
|
else:
|
||||||
sys.stderr.write("Station doesn't have a shipyard\n")
|
sys.stderr.write("Station doesn't have a shipyard\n")
|
||||||
|
|
||||||
|
@ -483,11 +483,7 @@ class AppWindow:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
elif not data['commander'].get('docked'):
|
elif not data['commander'].get('docked'):
|
||||||
if auto_update and not retrying:
|
if not self.status['text']:
|
||||||
# Silently retry if we got here by 'Automatically update on docking' and the server hasn't caught up
|
|
||||||
self.w.after(int(SERVER_RETRY * 1000), lambda:self.getandsend(event, True))
|
|
||||||
return # early exit to avoid starting cooldown count
|
|
||||||
elif not self.status['text']:
|
|
||||||
# Signal as error because the user might actually be docked but the server hosting the Companion API hasn't caught up
|
# Signal as error because the user might actually be docked but the server hosting the Companion API hasn't caught up
|
||||||
self.status['text'] = _("You're not docked at a station!")
|
self.status['text'] = _("You're not docked at a station!")
|
||||||
play_bad = True
|
play_bad = True
|
||||||
@ -522,11 +518,14 @@ class AppWindow:
|
|||||||
self.w.update_idletasks()
|
self.w.update_idletasks()
|
||||||
self.eddn.export_commodities(data, monitor.is_beta)
|
self.eddn.export_commodities(data, monitor.is_beta)
|
||||||
self.eddn.export_outfitting(data, monitor.is_beta)
|
self.eddn.export_outfitting(data, monitor.is_beta)
|
||||||
if monitor.stationtype != 'Outpost' and not data['lastStarport'].get('ships'):
|
if data['lastStarport'].get('ships'):
|
||||||
# API is flakey about shipyard info - silently retry if missing (<1s is usually sufficient - 5s for margin).
|
|
||||||
self.w.after(int(SERVER_RETRY * 1000), self.retry_for_shipyard)
|
|
||||||
else:
|
|
||||||
self.eddn.export_shipyard(data, monitor.is_beta)
|
self.eddn.export_shipyard(data, monitor.is_beta)
|
||||||
|
elif monitor.stationservices is not None and 'Shipyard' in monitor.stationservices:
|
||||||
|
# API is flakey about shipyard info - silently retry if missing (<1s is usually sufficient - 5s for margin).
|
||||||
|
self.w.after(int(SERVER_RETRY * 1000), lambda:self.retry_for_shipyard(2))
|
||||||
|
elif monitor.stationservices is None and monitor.stationtype != 'Outpost':
|
||||||
|
# Pre E:D 2.4 we don't know if we should have shipyard info. Retry once.
|
||||||
|
self.w.after(int(SERVER_RETRY * 1000), lambda:self.retry_for_shipyard(1))
|
||||||
if not old_status:
|
if not old_status:
|
||||||
self.status['text'] = ''
|
self.status['text'] = ''
|
||||||
|
|
||||||
@ -536,7 +535,6 @@ class AppWindow:
|
|||||||
# Companion API problem
|
# Companion API problem
|
||||||
except (companion.ServerError, companion.ServerLagging) as e:
|
except (companion.ServerError, companion.ServerLagging) as e:
|
||||||
if retrying:
|
if retrying:
|
||||||
print 'Lagging: %s,%s != %s,%s' % (data['lastSystem']['name'], data['commander']['docked'] and data['lastStarport']['name'] or 'undocked', monitor.system, monitor.station)
|
|
||||||
self.status['text'] = unicode(e)
|
self.status['text'] = unicode(e)
|
||||||
play_bad = True
|
play_bad = True
|
||||||
else:
|
else:
|
||||||
@ -562,14 +560,20 @@ class AppWindow:
|
|||||||
self.holdofftime = querytime + companion.holdoff
|
self.holdofftime = querytime + companion.holdoff
|
||||||
self.cooldown()
|
self.cooldown()
|
||||||
|
|
||||||
def retry_for_shipyard(self):
|
def retry_for_shipyard(self, tries):
|
||||||
# Try again to get shipyard data and send to EDDN. Don't report errors if can't get or send the data.
|
# Try again to get shipyard data and send to EDDN. Don't report errors if can't get or send the data.
|
||||||
try:
|
try:
|
||||||
data = self.session.query()
|
data = self.session.query()
|
||||||
if __debug__:
|
if __debug__:
|
||||||
print 'Retry for shipyard - ' + (data['commander'].get('docked') and (data['lastStarport'].get('ships') and 'Success' or 'Failure') or 'Undocked!')
|
print 'Retry for shipyard - ' + (data['commander'].get('docked') and (data['lastStarport'].get('ships') and 'Success' or 'Failure') or 'Undocked!')
|
||||||
if data['commander'].get('docked'): # might have undocked while we were waiting for retry in which case station data is unreliable
|
if not data['commander'].get('docked'):
|
||||||
|
pass # might have undocked while we were waiting for retry in which case station data is unreliable
|
||||||
|
elif (data['lastStarport'].get('ships') and
|
||||||
|
data['lastSystem']['name'] == monitor.system and
|
||||||
|
data['lastStarport']['name'] == monitor.station):
|
||||||
self.eddn.export_shipyard(data, monitor.is_beta)
|
self.eddn.export_shipyard(data, monitor.is_beta)
|
||||||
|
elif tries > 1: # bogus data - retry
|
||||||
|
self.w.after(int(SERVER_RETRY * 1000), lambda:self.retry_for_shipyard(tries-1))
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -202,7 +202,7 @@ class EDLogs(FileSystemEventHandler):
|
|||||||
if __debug__:
|
if __debug__:
|
||||||
print 'Stopping monitoring Journal'
|
print 'Stopping monitoring Journal'
|
||||||
self.currentdir = None
|
self.currentdir = None
|
||||||
self.version = self.mode = self.group = self.cmdr = self.planet = self.system = self.station = self.stationtype = self.coordinates = None
|
self.version = self.mode = self.group = self.cmdr = self.planet = self.system = self.station = self.stationtype = self.stationservices = self.coordinates = None
|
||||||
self.is_beta = False
|
self.is_beta = False
|
||||||
if self.observed:
|
if self.observed:
|
||||||
self.observed = None
|
self.observed = None
|
||||||
@ -311,6 +311,7 @@ class EDLogs(FileSystemEventHandler):
|
|||||||
self.system = None
|
self.system = None
|
||||||
self.station = None
|
self.station = None
|
||||||
self.stationtype = None
|
self.stationtype = None
|
||||||
|
self.stationservices = None
|
||||||
self.coordinates = None
|
self.coordinates = None
|
||||||
self.started = None
|
self.started = None
|
||||||
self.state = {
|
self.state = {
|
||||||
@ -338,6 +339,7 @@ class EDLogs(FileSystemEventHandler):
|
|||||||
self.system = None
|
self.system = None
|
||||||
self.station = None
|
self.station = None
|
||||||
self.stationtype = None
|
self.stationtype = None
|
||||||
|
self.stationservices = None
|
||||||
self.coordinates = None
|
self.coordinates = None
|
||||||
self.started = timegm(strptime(entry['timestamp'], '%Y-%m-%dT%H:%M:%SZ'))
|
self.started = timegm(strptime(entry['timestamp'], '%Y-%m-%dT%H:%M:%SZ'))
|
||||||
self.state.update({
|
self.state.update({
|
||||||
@ -383,6 +385,7 @@ class EDLogs(FileSystemEventHandler):
|
|||||||
elif entry['event'] in ['Undocked']:
|
elif entry['event'] in ['Undocked']:
|
||||||
self.station = None
|
self.station = None
|
||||||
self.stationtype = None
|
self.stationtype = None
|
||||||
|
self.stationservices = None
|
||||||
elif entry['event'] in ['Location', 'FSDJump', 'Docked']:
|
elif entry['event'] in ['Location', 'FSDJump', 'Docked']:
|
||||||
if entry['event'] == 'Location':
|
if entry['event'] == 'Location':
|
||||||
self.planet = entry.get('Body') if entry.get('BodyType') == 'Planet' else None
|
self.planet = entry.get('Body') if entry.get('BodyType') == 'Planet' else None
|
||||||
@ -395,6 +398,7 @@ class EDLogs(FileSystemEventHandler):
|
|||||||
(self.system, self.station) = (entry['StarSystem'] == 'ProvingGround' and 'CQC' or entry['StarSystem'],
|
(self.system, self.station) = (entry['StarSystem'] == 'ProvingGround' and 'CQC' or entry['StarSystem'],
|
||||||
entry.get('StationName')) # May be None
|
entry.get('StationName')) # May be None
|
||||||
self.stationtype = entry.get('StationType') # May be None
|
self.stationtype = entry.get('StationType') # May be None
|
||||||
|
self.stationservices = entry.get('StationServices') # None under E:D < 2.4
|
||||||
elif entry['event'] == 'SupercruiseExit':
|
elif entry['event'] == 'SupercruiseExit':
|
||||||
self.planet = entry.get('Body') if entry.get('BodyType') == 'Planet' else None
|
self.planet = entry.get('Body') if entry.get('BodyType') == 'Planet' else None
|
||||||
elif entry['event'] == 'SupercruiseEntry':
|
elif entry['event'] == 'SupercruiseEntry':
|
||||||
@ -467,6 +471,7 @@ class EDLogs(FileSystemEventHandler):
|
|||||||
self.system = None
|
self.system = None
|
||||||
self.station = None
|
self.station = None
|
||||||
self.stationtype = None
|
self.stationtype = None
|
||||||
|
self.stationservices = None
|
||||||
self.coordinates = None
|
self.coordinates = None
|
||||||
elif entry['event'] == 'ChangeCrewRole':
|
elif entry['event'] == 'ChangeCrewRole':
|
||||||
self.state['Role'] = entry['Role']
|
self.state['Role'] = entry['Role']
|
||||||
@ -477,6 +482,7 @@ class EDLogs(FileSystemEventHandler):
|
|||||||
self.system = None
|
self.system = None
|
||||||
self.station = None
|
self.station = None
|
||||||
self.stationtype = None
|
self.stationtype = None
|
||||||
|
self.stationservices = None
|
||||||
self.coordinates = None
|
self.coordinates = None
|
||||||
|
|
||||||
return entry
|
return entry
|
||||||
|
Loading…
x
Reference in New Issue
Block a user