refactor: bind hot_reload event via EventDispatcher, add on_hot_reload to UAPIData

This commit is contained in:
yumoqing 2026-06-01 18:10:31 +08:00
parent 4360f34576
commit e735070007
4 changed files with 10 additions and 1 deletions

Binary file not shown.

Binary file not shown.

View File

@ -64,7 +64,13 @@ class UAPIData:
self.apidata = {} self.apidata = {}
self.apikeys = {} self.apikeys = {}
self.org_users = {} self.org_users = {}
def on_hot_reload(self, data=None):
"""Event handler for hot_reload event. Clears all caches."""
self.apidata.clear()
self.apikeys.clear()
self.org_users.clear()
async def get_userapikey(self, appid, callerid): async def get_userapikey(self, appid, callerid):
users = await self.get_apiusers(appid) users = await self.get_apiusers(appid)
for u in users: for u in users:

View File

@ -32,6 +32,9 @@ def load_uapi():
g.get_my_uptasks = get_my_uptasks g.get_my_uptasks = get_my_uptasks
g.uptask_feedback = uptask_feedback g.uptask_feedback = uptask_feedback
g.uptask_started = uptask_started g.uptask_started = uptask_started
# Bind hot_reload event — instance method, WeakMethod safe (stored on g)
if hasattr(g, 'event_dispatcher'):
g.event_dispatcher.bind('hot_reload', g.uapi_data.on_hot_reload)
# USAGE in dspy # USAGE in dspy