Allow to customize fetch timeout when requesting prices
This commit is contained in:
@@ -16,7 +16,7 @@ class ItemCompare(wx.Panel):
|
||||
def __init__(self, parent, stuff, item, items, context=None):
|
||||
# Start dealing with Price stuff to get that thread going
|
||||
sPrice = ServicePrice.getInstance()
|
||||
sPrice.getPrices(items, self.UpdateList)
|
||||
sPrice.getPrices(items, self.UpdateList, fetchTimeout=90)
|
||||
|
||||
wx.Panel.__init__(self, parent)
|
||||
mainSizer = wx.BoxSizer(wx.VERTICAL)
|
||||
|
||||
@@ -83,7 +83,7 @@ class PriceViewFull(StatsView):
|
||||
fit_items = Price.fitItemsList(fit)
|
||||
|
||||
sPrice = Price.getInstance()
|
||||
sPrice.getPrices(fit_items, self.processPrices)
|
||||
sPrice.getPrices(fit_items, self.processPrices, fetchTimeout=30)
|
||||
self.labelEMStatus.SetLabel("Updating prices...")
|
||||
|
||||
self.refreshPanelPrices(fit)
|
||||
|
||||
@@ -77,7 +77,7 @@ class PriceViewMinimal(StatsView):
|
||||
fit_items = Price.fitItemsList(fit)
|
||||
|
||||
sPrice = Price.getInstance()
|
||||
sPrice.getPrices(fit_items, self.processPrices)
|
||||
sPrice.getPrices(fit_items, self.processPrices, fetchTimeout=30)
|
||||
self.labelEMStatus.SetLabel("Updating prices...")
|
||||
|
||||
self.refreshPanelPrices(fit)
|
||||
|
||||
@@ -33,7 +33,11 @@ from gui.utils.numberFormatter import formatAmount
|
||||
def formatPrice(stuff, priceObj):
|
||||
textItems = []
|
||||
if priceObj.price:
|
||||
mult = stuff.amount if isinstance(stuff, (Drone, Cargo, Fighter)) else 1
|
||||
mult = 1
|
||||
if isinstance(stuff, (Drone, Cargo)):
|
||||
mult = stuff.amount
|
||||
elif isinstance(stuff, Fighter):
|
||||
mult = stuff.amountActive
|
||||
textItems.append(formatAmount(priceObj.price * mult, 3, 3, 9, currency=True))
|
||||
if priceObj.status in (PriceStatus.fetchFail, PriceStatus.fetchTimeout):
|
||||
textItems.append("(!)")
|
||||
@@ -73,7 +77,7 @@ class Price(ViewColumn):
|
||||
|
||||
display.SetItem(colItem)
|
||||
|
||||
sPrice.getPrices([mod.item], callback, True)
|
||||
sPrice.getPrices([mod.item], callback, waitforthread=True)
|
||||
|
||||
def getImageId(self, mod):
|
||||
return -1
|
||||
|
||||
@@ -33,14 +33,14 @@ class EveMarketData:
|
||||
|
||||
name = "eve-marketdata.com"
|
||||
|
||||
def __init__(self, priceMap, system, timeout):
|
||||
def __init__(self, priceMap, system, fetchTimeout):
|
||||
data = {}
|
||||
baseurl = "https://eve-marketdata.com/api/item_prices.xml"
|
||||
data["system_id"] = system
|
||||
data["type_ids"] = ','.join(str(typeID) for typeID in priceMap)
|
||||
|
||||
network = Network.getInstance()
|
||||
data = network.request(baseurl, network.PRICES, params=data, timeout=timeout)
|
||||
data = network.request(baseurl, network.PRICES, params=data, timeout=fetchTimeout)
|
||||
xml = minidom.parseString(data.text)
|
||||
types = xml.getElementsByTagName("eve").item(0).getElementsByTagName("price")
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ class EveMarketer:
|
||||
|
||||
name = "evemarketer"
|
||||
|
||||
def __init__(self, priceMap, system, timeout):
|
||||
def __init__(self, priceMap, system, fetchTimeout):
|
||||
data = {}
|
||||
baseurl = "https://api.evemarketer.com/ec/marketstat"
|
||||
|
||||
@@ -41,7 +41,7 @@ class EveMarketer:
|
||||
data["typeid"] = {typeID for typeID in priceMap}
|
||||
|
||||
network = Network.getInstance()
|
||||
data = network.request(baseurl, network.PRICES, params=data, timeout=timeout)
|
||||
data = network.request(baseurl, network.PRICES, params=data, timeout=fetchTimeout)
|
||||
xml = minidom.parseString(data.text)
|
||||
types = xml.getElementsByTagName("marketstat").item(0).getElementsByTagName("type")
|
||||
# Cycle through all types we've got from request
|
||||
|
||||
@@ -64,7 +64,7 @@ class Price:
|
||||
return cls.instance
|
||||
|
||||
@classmethod
|
||||
def fetchPrices(cls, prices, timeout=5):
|
||||
def fetchPrices(cls, prices, fetchTimeout):
|
||||
"""Fetch all prices passed to this method"""
|
||||
|
||||
# Dictionary for our price objects
|
||||
@@ -112,7 +112,7 @@ class Price:
|
||||
sourcesToTry.remove(curr)
|
||||
try:
|
||||
sourceCls = cls.sources.get(curr)
|
||||
sourceCls(priceMap, cls.systemsList[sFit.serviceFittingOptions["priceSystem"]], timeout)
|
||||
sourceCls(priceMap, cls.systemsList[sFit.serviceFittingOptions["priceSystem"]], fetchTimeout)
|
||||
except TimeoutError:
|
||||
pyfalog.warning("Price fetch timeout for source {}".format(curr))
|
||||
timeouts[curr] = True
|
||||
@@ -166,7 +166,7 @@ class Price:
|
||||
|
||||
return item.price.price
|
||||
|
||||
def getPrices(self, objitems, callback, waitforthread=False):
|
||||
def getPrices(self, objitems, callback, fetchTimeout=30, waitforthread=False):
|
||||
"""Get prices for multiple typeIDs"""
|
||||
requests = []
|
||||
sMkt = Market.getInstance()
|
||||
@@ -186,7 +186,7 @@ class Price:
|
||||
if waitforthread:
|
||||
self.priceWorkerThread.setToWait(requests, cb)
|
||||
else:
|
||||
self.priceWorkerThread.trigger(requests, cb)
|
||||
self.priceWorkerThread.trigger(requests, cb, fetchTimeout)
|
||||
|
||||
def clearPriceCache(self):
|
||||
pyfalog.debug("Clearing Prices")
|
||||
@@ -206,11 +206,11 @@ class PriceWorkerThread(threading.Thread):
|
||||
queue = self.queue
|
||||
while True:
|
||||
# Grab our data
|
||||
callback, requests = queue.get()
|
||||
callback, requests, fetchTimeout = queue.get()
|
||||
|
||||
# Grab prices, this is the time-consuming part
|
||||
if len(requests) > 0:
|
||||
Price.fetchPrices(requests)
|
||||
Price.fetchPrices(requests, fetchTimeout)
|
||||
|
||||
wx.CallAfter(callback)
|
||||
queue.task_done()
|
||||
@@ -222,14 +222,13 @@ class PriceWorkerThread(threading.Thread):
|
||||
for callback in callbacks:
|
||||
wx.CallAfter(callback)
|
||||
|
||||
def trigger(self, prices, callbacks):
|
||||
self.queue.put((callbacks, prices))
|
||||
def trigger(self, prices, callbacks, fetchTimeout):
|
||||
self.queue.put((callbacks, prices, fetchTimeout))
|
||||
|
||||
def setToWait(self, prices, callback):
|
||||
for x in prices:
|
||||
if x.typeID not in self.wait:
|
||||
self.wait[x.typeID] = []
|
||||
self.wait[x.typeID].append(callback)
|
||||
for price in prices:
|
||||
callbacks = self.wait.setdefault(price.typeID, [])
|
||||
callbacks.append(callback)
|
||||
|
||||
|
||||
# Import market sources only to initialize price source modules, they register on their own
|
||||
|
||||
Reference in New Issue
Block a user