|
11 | 11 | import logging |
12 | 12 |
|
13 | 13 | from aiohttp import web |
14 | | -from servicelib.aiohttp.application_setup import ModuleCategory, app_module_setup |
| 14 | +from servicelib.aiohttp.application_setup import ( |
| 15 | + ModuleCategory, |
| 16 | + app_module_setup, |
| 17 | + ensure_single_setup, |
| 18 | +) |
15 | 19 |
|
16 | 20 | _logger = logging.getLogger(__name__) |
17 | 21 |
|
18 | 22 |
|
19 | | -@app_module_setup( |
20 | | - __name__, |
21 | | - ModuleCategory.ADDON, |
22 | | - depends=["simcore_service_webserver.db"], |
23 | | - settings_name="WEBSERVER_PRODUCTS", |
24 | | - logger=_logger, |
25 | | -) |
26 | | -def setup_products(app: web.Application, *, rpc_enabled: bool = True): |
| 23 | +@ensure_single_setup(f"{__name__}.without_rpc", logger=_logger) |
| 24 | +def setup_products_without_rpc(app: web.Application): |
27 | 25 | # |
28 | 26 | # NOTE: internal import speeds up booting app |
29 | 27 | # specially if this plugin is not set up to be loaded |
30 | 28 | # |
31 | 29 | from ..constants import APP_SETTINGS_KEY |
32 | 30 | from . import _web_events, _web_middlewares |
33 | | - from ._controller import rest, rpc |
| 31 | + from ._controller import rest |
34 | 32 |
|
35 | 33 | assert app[APP_SETTINGS_KEY].WEBSERVER_PRODUCTS is True # nosec |
36 | 34 |
|
37 | 35 | # rest API |
38 | 36 | app.middlewares.append(_web_middlewares.discover_product_middleware) |
39 | 37 | app.router.add_routes(rest.routes) |
40 | 38 |
|
41 | | - # rpc API (optional) |
42 | | - if rpc_enabled: |
43 | | - rpc.setup_rpc(app) |
44 | | - else: |
45 | | - _logger.info("Skipping RPC api in products plugin") |
46 | | - |
47 | 39 | _web_events.setup_web_events(app) |
| 40 | + |
| 41 | + |
| 42 | +@app_module_setup( |
| 43 | + __name__, |
| 44 | + ModuleCategory.ADDON, |
| 45 | + depends=["simcore_service_webserver.db"], |
| 46 | + settings_name="WEBSERVER_PRODUCTS", |
| 47 | + logger=_logger, |
| 48 | +) |
| 49 | +def setup_products(app: web.Application): |
| 50 | + from ._controller import rpc |
| 51 | + |
| 52 | + setup_products_without_rpc(app) |
| 53 | + |
| 54 | + # rpc API (optional) |
| 55 | + rpc.setup_rpc(app) |
0 commit comments