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