Merge branch 'pricing_v2' into development

This commit is contained in:
blitzmann
2017-04-10 20:46:57 -04:00
16 changed files with 402 additions and 179 deletions

View File

@@ -68,7 +68,7 @@ else:
saveddata_meta = None
# Lock controlling any changes introduced to session
sd_lock = threading.Lock()
sd_lock = threading.RLock()
# Import all the definitions for all our database stuff
# noinspection PyPep8

View File

@@ -23,6 +23,7 @@ from sqlalchemy.orm import reconstructor
import eos.db
from eqBase import EqBase
from eos.saveddata.price import Price as types_Price
try:
from collections import OrderedDict
@@ -438,6 +439,39 @@ class Item(EqBase):
return False
@property
def price(self):
try:
if not hasattr(self, "__price"):
self.__price = types_Price(self.ID)
# Get the price from the DB
price = eos.db.getPrice(self.ID)
if price:
if self.__price.time > price.time:
# The object is newer than the DB, update the DB.
eos.db.add(self.__price)
eos.db.commit()
if self.__price.time < price.time:
# DB object is newer than local object, update the local object
self.__price = price
else:
pyfalog.debug("Unable to fetch item price from database.")
return self.__price
except Exception as e:
# We want to catch our failure and log it, but don't bail out for a single missing price tag.
pyfalog.error("Failed to get price for typeID: {0}", self.ID)
pyfalog.error(e)
if not self.__price.price:
self.__price.price = 0
self.__price.failed = True
return self.__price
def __repr__(self):
return "Item(ID={}, name={}) at {}".format(
self.ID, self.name, hex(id(self))

View File

@@ -21,6 +21,9 @@
import time
from sqlalchemy.orm import reconstructor
from logbook import Logger
pyfalog = Logger(__name__)
class Price(object):
@@ -29,7 +32,6 @@ class Price(object):
self.time = 0
self.price = 0
self.failed = None
self.__item = None
@reconstructor
def init(self):