diff --git a/xconn/_client/async_.py b/xconn/_client/async_.py index a138a04..ac0fd9c 100644 --- a/xconn/_client/async_.py +++ b/xconn/_client/async_.py @@ -41,6 +41,22 @@ async def _setup(app: App, session: AsyncSession): await subscribe_async(session, uri, func) print(f"Subscribed topic {uri}") + if app.schema_procedure is not None and app.schema_procedure != "": + docs = [] + + for uri, func in app.procedures.items(): + docs.append(collect_docs(uri, func, "procedure")) + + for uri, func in app.topics.items(): + docs.append(collect_docs(uri, func, "topic")) + + async def get_schema(_: Invocation) -> Result: + return Result(args=docs) + + options = RegisterOptions(invoke=InvokeOptions.ROUNDROBIN) + await session.register(app.schema_procedure, get_schema, options=options) + print(f"serving schema at procedure {app.schema_procedure}") + async def _connect_async(app: App, config: ClientConfig, start_router: bool = False): if start_router: @@ -74,22 +90,6 @@ async def on_disconnect(): session = await client.connect(config.url, config.realm, on_connect, on_disconnect) await _setup(app, session) - if app.schema_procedure is not None and app.schema_procedure != "": - docs = [] - - for uri, func in app.procedures.items(): - docs.append(collect_docs(uri, func, "procedure")) - - for uri, func in app.topics.items(): - docs.append(collect_docs(uri, func, "topic")) - - async def get_schema(_: Invocation) -> Result: - return Result(args=docs) - - options = RegisterOptions(invoke=InvokeOptions.ROUNDROBIN) - await session.register(app.schema_procedure, get_schema, options=options) - print(f"serving schema at procedure {app.schema_procedure}") - def connect_async(app: str, config: ClientConfig, start_router: bool = False, directory: str = "."): app = import_app(app, directory) diff --git a/xconn/_client/sync.py b/xconn/_client/sync.py index 9500e2e..37d100e 100644 --- a/xconn/_client/sync.py +++ b/xconn/_client/sync.py @@ -42,6 +42,22 @@ def _setup(app: App, session: Session): for uri, func in app.topics.items(): subscribe_sync(session, uri, func) + if app.schema_procedure is not None and app.schema_procedure != "": + docs = [] + + for uri, func in app.procedures.items(): + docs.append(collect_docs(uri, func, "procedure")) + + for uri, func in app.topics.items(): + docs.append(collect_docs(uri, func, "topic")) + + def get_schema(_: Invocation) -> Result: + return Result(args=docs) + + options = RegisterOptions(invoke=InvokeOptions.ROUNDROBIN) + session.register(app.schema_procedure, get_schema, options=options) + print(f"serving schema at procedure {app.schema_procedure}") + def _connect_sync(app: App, config: ClientConfig, start_router: bool = False, directory: str = "."): ws_url = urlparse(config.url) @@ -78,22 +94,6 @@ def on_disconnect(): session = client.connect(config.url, config.realm, on_connect, on_disconnect) _setup(app, session) - if app.schema_procedure is not None and app.schema_procedure != "": - docs = [] - - for uri, func in app.procedures.items(): - docs.append(collect_docs(uri, func, "procedure")) - - for uri, func in app.topics.items(): - docs.append(collect_docs(uri, func, "topic")) - - def get_schema(_: Invocation) -> Result: - return Result(args=docs) - - options = RegisterOptions(invoke=InvokeOptions.ROUNDROBIN) - session.register(app.schema_procedure, get_schema, options=options) - print(f"serving schema at procedure {app.schema_procedure}") - def connect_sync(app: str, config: ClientConfig, start_router: bool = False, directory: str = "."): imported_app = import_app(app, directory)