Merge branch 'pricing'

This commit is contained in:
blitzmann
2015-07-03 02:38:23 -04:00
7 changed files with 46 additions and 63 deletions

View File

@@ -71,6 +71,7 @@ class ShipBrowserWorkerThread(threading.Thread):
class PriceWorkerThread(threading.Thread):
def run(self):
self.queue = Queue.Queue()
self.wait = {}
self.processUpdates()
def processUpdates(self):
@@ -86,9 +87,21 @@ class PriceWorkerThread(threading.Thread):
wx.CallAfter(callback)
queue.task_done()
# After we fetch prices, go through the list of waiting items and call their callbacks
for price in requests:
callbacks = self.wait.pop(price.typeID, None)
if callbacks:
for callback in callbacks:
wx.CallAfter(callback)
def trigger(self, prices, callbacks):
self.queue.put((callbacks, prices))
def setToWait(self, itemID, callback):
if itemID not in self.wait:
self.wait[itemID] = []
self.wait[itemID].append(callback)
class SearchWorkerThread(threading.Thread):
def run(self):
self.cv = threading.Condition()
@@ -693,10 +706,6 @@ class Market():
self.priceCache[typeID] = price
if not price.isValid:
# if the price has expired
price.price = None
return price
def getPricesNow(self, typeIDs):
@@ -719,6 +728,21 @@ class Market():
self.priceWorkerThread.trigger(requests, cb)
def waitForPrice(self, item, callback):
"""
Wait for prices to be fetched and callback when finished. This is used with the column prices for modules.
Instead of calling them individually, we set them to wait until the entire fit price is called and calculated
(see GH #290)
"""
def cb():
try:
callback(item)
except:
pass
self.priceWorkerThread.setToWait(item.ID, cb)
def clearPriceCache(self):
self.priceCache.clear()
deleted_rows = eos.db.clearPrices()

View File

@@ -71,7 +71,6 @@ class Price():
# Attempt to send request and process it
try:
len(priceMap)
network = service.Network.getInstance()
data = network.request(baseurl, network.PRICES, data)
xml = minidom.parse(data)
@@ -102,7 +101,7 @@ class Price():
for typeID in priceMap.keys():
priceobj = priceMap[typeID]
priceobj.time = time.time() + TIMEOUT
priceobj.failed = None
priceobj.failed = True
del priceMap[typeID]
except:
# all other errors will pass and continue onward to the REREQUEST delay
@@ -111,6 +110,5 @@ class Price():
# if we get to this point, then we've got an error. Set to REREQUEST delay
for typeID in priceMap.keys():
priceobj = priceMap[typeID]
priceobj.price = 0
priceobj.time = time.time() + REREQUEST
priceobj.failed = None
priceobj.failed = True