refactor: migrate pricing_data to share_cache Redis
This commit is contained in:
parent
e3909fef53
commit
3483d16c58
@ -189,14 +189,15 @@ def data_mapping(ns, name, v):
|
|||||||
return v
|
return v
|
||||||
|
|
||||||
class PricingProgram:
|
class PricingProgram:
|
||||||
pricing_data = {}
|
pass # pricing_data moved to Redis share_cache
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def on_hot_reload(data=None):
|
def on_hot_reload(data=None):
|
||||||
"""Event handler for hot_reload event. Clears pricing cache."""
|
"""Event handler for hot_reload event. Clears pricing cache."""
|
||||||
from appPublic.log import debug
|
from appPublic.log import debug
|
||||||
debug(f'[pricing] on_hot_reload called, clearing pricing_data (data={data})')
|
debug(f'[pricing] on_hot_reload called, clearing pricing_data (data={data})')
|
||||||
PricingProgram.pricing_data.clear()
|
from appPublic.share_cache import cache_invalidate
|
||||||
|
await cache_invalidate('pricing')
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
async def get_pricing_program(ppid):
|
async def get_pricing_program(ppid):
|
||||||
@ -431,10 +432,9 @@ class PricingProgram:
|
|||||||
async def get_ppid_pricing(ppid):
|
async def get_ppid_pricing(ppid):
|
||||||
dat = curDateString()
|
dat = curDateString()
|
||||||
k = f'{ppid}.{dat}'
|
k = f'{ppid}.{dat}'
|
||||||
if _cache_enabled():
|
d = await cache_get('pricing', k, ttl=300)
|
||||||
d = PricingProgram.pricing_data.get(k)
|
if d:
|
||||||
if d:
|
return d
|
||||||
return d
|
|
||||||
env = ServerEnv()
|
env = ServerEnv()
|
||||||
async with get_sor_context(env, 'pricing') as sor:
|
async with get_sor_context(env, 'pricing') as sor:
|
||||||
sql = """select a.name, a.ownerid, a.providerid, a.currency,
|
sql = """select a.name, a.ownerid, a.providerid, a.currency,
|
||||||
@ -454,17 +454,8 @@ class PricingProgram:
|
|||||||
exception(f'{e}')
|
exception(f'{e}')
|
||||||
raise e
|
raise e
|
||||||
d = recs[0]
|
d = recs[0]
|
||||||
if _cache_enabled():
|
from appPublic.share_cache import cache_set
|
||||||
PricingProgram.pricing_data[k] = d
|
await cache_set('pricing', k, d, ttl=300)
|
||||||
dates = PricingProgram.pricing_data.get(ppid, [])
|
|
||||||
dates.append(dat)
|
|
||||||
dates_cnt = len(dates)
|
|
||||||
if dates_cnt > 2:
|
|
||||||
for i in range(dates_cnt - 2):
|
|
||||||
dk = f'{ppid}.{dates[i]}'
|
|
||||||
PricingProgram.pricing_data[dk]
|
|
||||||
dates = dates[-2:]
|
|
||||||
PricingProgram.pricing_data[ppid] = dates
|
|
||||||
return d
|
return d
|
||||||
|
|
||||||
async def buffered_charging(ppid, data):
|
async def buffered_charging(ppid, data):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user