@@ -37,12 +37,8 @@ class WorkspaceMuxRuleDoesNotExistError(WorkspaceCrudError):
3737
3838class WorkspaceCrud :
3939
40- def __init__ (
41- self ,
42- mux_registry : rulematcher .MuxingRulesinWorkspaces = rulematcher .get_muxing_rules_registry (),
43- ):
40+ def __init__ (self ):
4441 self ._db_reader = DbReader ()
45- self ._mux_registry = mux_registry
4642
4743 async def add_workspace (self , new_workspace_name : str ) -> WorkspaceRow :
4844 """
@@ -141,7 +137,8 @@ async def activate_workspace(self, workspace_name: str):
141137 await db_recorder .update_session (session )
142138
143139 # Ensure the mux registry is updated
144- self ._mux_registry .set_active_workspace (workspace .name )
140+ mux_registry = await rulematcher .get_muxing_rules_registry ()
141+ await mux_registry .set_active_workspace (workspace .name )
145142 return
146143
147144 async def recover_workspace (self , workspace_name : str ):
@@ -198,7 +195,8 @@ async def soft_delete_workspace(self, workspace_name: str):
198195 raise WorkspaceCrudError (f"Error deleting workspace { workspace_name } " )
199196
200197 # Remove the muxes from the registry
201- del self ._mux_registry [workspace_name ]
198+ mux_registry = await rulematcher .get_muxing_rules_registry ()
199+ await mux_registry .delete_ws_rules (workspace_name )
202200 return
203201
204202 async def hard_delete_workspace (self , workspace_name : str ):
@@ -293,7 +291,8 @@ async def set_muxes(self, workspace_name: str, muxes):
293291 priority += 1
294292
295293 # Set routing list for the workspace
296- self ._mux_registry [workspace_name ] = matchers
294+ mux_registry = await rulematcher .get_muxing_rules_registry ()
295+ await mux_registry .set_ws_rules (workspace_name , matchers )
297296
298297 async def get_routing_for_mux (self , mux ) -> rulematcher .ModelRoute :
299298 """Get the routing for a mux
@@ -359,7 +358,8 @@ async def initialize_mux_registry(self) -> None:
359358
360359 active_ws = await self .get_active_workspace ()
361360 if active_ws :
362- self ._mux_registry .set_active_workspace (active_ws .name )
361+ mux_registry = await rulematcher .get_muxing_rules_registry ()
362+ await mux_registry .set_active_workspace (active_ws .name )
363363
364364 await self .repopulate_mux_cache ()
365365
@@ -369,12 +369,14 @@ async def repopulate_mux_cache(self) -> None:
369369 # Get all workspaces
370370 workspaces = await self .get_workspaces ()
371371
372+ mux_registry = await rulematcher .get_muxing_rules_registry ()
373+
372374 # Remove any workspaces from cache that are not in the database
373375 ws_names = set (ws .name for ws in workspaces )
374- cached_ws = set (self . _mux_registry . keys ())
376+ cached_ws = set (await mux_registry . get_registries ())
375377 ws_to_remove = cached_ws - ws_names
376378 for ws in ws_to_remove :
377- del self . _mux_registry [ ws ]
379+ await mux_registry . delete_ws_rules ( ws )
378380
379381 # For each workspace, get the muxes and set them in the registry
380382 for ws in workspaces :
@@ -386,4 +388,4 @@ async def repopulate_mux_cache(self) -> None:
386388 route = await self .get_routing_for_db_mux (mux )
387389 matchers .append (rulematcher .MuxingMatcherFactory .create (mux , route ))
388390
389- self . _mux_registry [ ws .name ] = matchers
391+ await mux_registry . set_ws_rules ( ws .name , matchers )
0 commit comments