bugfix
This commit is contained in:
parent
1677d18704
commit
c85b9527c3
@ -7,6 +7,22 @@ from pricing.pricing import (
|
|||||||
)
|
)
|
||||||
from ahserver.serverenv import ServerEnv
|
from ahserver.serverenv import ServerEnv
|
||||||
|
|
||||||
|
def _bind_pricing_events(dbpools, dbname):
|
||||||
|
"""Bind database events to Pricing cache invalidation handlers."""
|
||||||
|
bindings = [
|
||||||
|
# pricing_program_timing: 新增(已有 u 的 reload_pp_data,但统一用新方法)
|
||||||
|
(f'{dbname}:pricing_program_timing:c:after', PricingProgram.on_timing_create),
|
||||||
|
(f'{dbname}:pricing_program_timing:u:after', PricingProgram.reload_pp_data),
|
||||||
|
(f'{dbname}:pricing_program_timing:d:after', PricingProgram.on_timing_delete),
|
||||||
|
# pricing_program: 增删改均刷新该程序的全部缓存
|
||||||
|
(f'{dbname}:pricing_program:c:after', PricingProgram.reload_pricing_program),
|
||||||
|
(f'{dbname}:pricing_program:u:after', PricingProgram.reload_pricing_program),
|
||||||
|
(f'{dbname}:pricing_program:d:after', PricingProgram.reload_pricing_program),
|
||||||
|
]
|
||||||
|
for event_name, handler in bindings:
|
||||||
|
dbpools.bind(event_name, handler)
|
||||||
|
debug(f'Pricing event bound: {event_name}')
|
||||||
|
|
||||||
def load_pricing():
|
def load_pricing():
|
||||||
env = ServerEnv()
|
env = ServerEnv()
|
||||||
env.get_pricing_program = get_pricing_program
|
env.get_pricing_program = get_pricing_program
|
||||||
@ -19,8 +35,9 @@ def load_pricing():
|
|||||||
env.test_pricing = test_pricing
|
env.test_pricing = test_pricing
|
||||||
dbpools = DBPools()
|
dbpools = DBPools()
|
||||||
dbname = env.get_module_dbname('pricing')
|
dbname = env.get_module_dbname('pricing')
|
||||||
ename = f'{dbname}:pricing_program_timing:u:after'
|
if dbname:
|
||||||
debug(f'bind event({ename}) ....')
|
_bind_pricing_events(dbpools, dbname)
|
||||||
|
debug(f'Pricing event listeners bound for database: {dbname}')
|
||||||
dbpools.bind(ename, PricingProgram.reload_pp_data)
|
else:
|
||||||
|
debug('Pricing event listeners skipped: no database configured for pricing module')
|
||||||
|
|
||||||
|
|||||||
@ -304,6 +304,17 @@ class PricingProgram:
|
|||||||
exception(e)
|
exception(e)
|
||||||
raise Exception(e)
|
raise Exception(e)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
async def _invalidate_ppid_cache(ppid):
|
||||||
|
"""清除指定 ppid 的所有缓存条目。"""
|
||||||
|
dates = PricingProgram.pricing_data.get(ppid, [])
|
||||||
|
for d in dates:
|
||||||
|
k = f'{ppid}.{d}'
|
||||||
|
if k in PricingProgram.pricing_data:
|
||||||
|
del PricingProgram.pricing_data[k]
|
||||||
|
if ppid in PricingProgram.pricing_data:
|
||||||
|
del PricingProgram.pricing_data[ppid]
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
async def reload_pp_data(ppt):
|
async def reload_pp_data(ppt):
|
||||||
env = ServerEnv()
|
env = ServerEnv()
|
||||||
@ -321,6 +332,48 @@ class PricingProgram:
|
|||||||
del PricingProgram.pricing_data[k]
|
del PricingProgram.pricing_data[k]
|
||||||
await PricingProgram.get_ppid_pricing(ppid)
|
await PricingProgram.get_ppid_pricing(ppid)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
async def reload_pricing_program(data):
|
||||||
|
"""处理 pricing_program 表的增删改事件,刷新该程序的全部缓存。"""
|
||||||
|
ppid = data.get('id')
|
||||||
|
if not ppid:
|
||||||
|
exception(f'ppid (id) not found in pricing_program event data: {data}')
|
||||||
|
return
|
||||||
|
debug(f'--EventHandle pricing_program c/u/d: {data}')
|
||||||
|
await PricingProgram._invalidate_ppid_cache(ppid)
|
||||||
|
try:
|
||||||
|
await PricingProgram.get_ppid_pricing(ppid)
|
||||||
|
except Exception as e:
|
||||||
|
debug(f'reload_pricing_program: get_ppid_pricing failed for ppid={ppid}: {e}')
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
async def on_timing_create(data):
|
||||||
|
"""处理 pricing_program_timing 新增事件。"""
|
||||||
|
ppid = data.get('ppid')
|
||||||
|
if not ppid:
|
||||||
|
exception(f'ppid not found in timing create event data: {data}')
|
||||||
|
return
|
||||||
|
debug(f'--EventHandle timing create: {data}')
|
||||||
|
await PricingProgram._invalidate_ppid_cache(ppid)
|
||||||
|
try:
|
||||||
|
await PricingProgram.get_ppid_pricing(ppid)
|
||||||
|
except Exception as e:
|
||||||
|
debug(f'on_timing_create: get_ppid_pricing failed for ppid={ppid}: {e}')
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
async def on_timing_delete(data):
|
||||||
|
"""处理 pricing_program_timing 删除事件。"""
|
||||||
|
ppid = data.get('ppid')
|
||||||
|
if not ppid:
|
||||||
|
exception(f'ppid not found in timing delete event data: {data}')
|
||||||
|
return
|
||||||
|
debug(f'--EventHandle timing delete: {data}')
|
||||||
|
await PricingProgram._invalidate_ppid_cache(ppid)
|
||||||
|
try:
|
||||||
|
await PricingProgram.get_ppid_pricing(ppid)
|
||||||
|
except Exception as e:
|
||||||
|
debug(f'on_timing_delete: get_ppid_pricing failed for ppid={ppid}: {e}')
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
async def get_ppid_pricing(ppid):
|
async def get_ppid_pricing(ppid):
|
||||||
dat = curDateString()
|
dat = curDateString()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user