Sanic multi-application server (#2347)
This commit is contained in:
@@ -10,12 +10,14 @@ from .base import BaseScheme
|
||||
|
||||
class OptionalDispatchEvent(BaseScheme):
|
||||
ident = "ODE"
|
||||
SYNC_SIGNAL_NAMESPACES = "http."
|
||||
|
||||
def __init__(self, app) -> None:
|
||||
super().__init__(app)
|
||||
|
||||
self._sync_events()
|
||||
self._registered_events = [
|
||||
signal.path for signal in app.signal_router.routes
|
||||
signal.name for signal in app.signal_router.routes
|
||||
]
|
||||
|
||||
def run(self, method, module_globals):
|
||||
@@ -31,6 +33,35 @@ class OptionalDispatchEvent(BaseScheme):
|
||||
|
||||
return exec_locals[method.__name__]
|
||||
|
||||
def _sync_events(self):
|
||||
all_events = set()
|
||||
app_events = {}
|
||||
for app in self.app.__class__._app_registry.values():
|
||||
if app.state.server_info:
|
||||
app_events[app] = {
|
||||
signal.name for signal in app.signal_router.routes
|
||||
}
|
||||
all_events.update(app_events[app])
|
||||
|
||||
for app, events in app_events.items():
|
||||
missing = {
|
||||
x
|
||||
for x in all_events.difference(events)
|
||||
if any(x.startswith(y) for y in self.SYNC_SIGNAL_NAMESPACES)
|
||||
}
|
||||
if missing:
|
||||
was_finalized = app.signal_router.finalized
|
||||
if was_finalized: # no cov
|
||||
app.signal_router.reset()
|
||||
for event in missing:
|
||||
app.signal(event)(self.noop)
|
||||
if was_finalized: # no cov
|
||||
app.signal_router.finalize()
|
||||
|
||||
@staticmethod
|
||||
async def noop(**_): # no cov
|
||||
...
|
||||
|
||||
|
||||
class RemoveDispatch(NodeTransformer):
|
||||
def __init__(self, registered_events, verbosity: int = 0) -> None:
|
||||
|
||||
Reference in New Issue
Block a user