Skip to content

Commit 37285a9

Browse files
committed
use app factory
1 parent 5a328fd commit 37285a9

File tree

24 files changed

+30
-32
lines changed

24 files changed

+30
-32
lines changed

services/api-server/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ define _create_and_validate_openapi
3030
# generating openapi specs file under $< (NOTE: Skips DEV FEATURES since this OAS is the 'offically released'!)
3131
@source .env; \
3232
export API_SERVER_DEV_FEATURES_ENABLED=$1; \
33-
python3 -c "import json; from $(APP_PACKAGE_NAME).main import *; print( json.dumps(the_app.openapi(), indent=2) )" > $@
33+
python3 -c "import json; from $(APP_PACKAGE_NAME).main import *; print( json.dumps(app_factory().openapi(), indent=2) )" > $@
3434

3535
# validates OAS file: $@
3636
docker run --rm \

services/api-server/src/simcore_service_api_server/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ def run():
1818
"""Runs application"""
1919
typer.secho("Sorry, this entrypoint is intentionally disabled. Use instead")
2020
typer.secho(
21-
"$ uvicorn simcore_service_api_server.main:the_app",
21+
"$ uvicorn --factory simcore_service_api_server.main:app_factory",
2222
fg=typer.colors.BLUE,
2323
)

services/api-server/src/simcore_service_api_server/main.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
from simcore_service_api_server.core.application import init_app
1010
from simcore_service_api_server.core.settings import ApplicationSettings
1111

12-
# SINGLETON FastAPI app
13-
the_app: FastAPI = init_app()
14-
1512
_logger = logging.getLogger(__name__)
1613

1714
_NOISY_LOGGERS: Final[tuple[str, ...]] = (

services/api-server/tests/unit/test_cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def test_cli_list_settings(cli_runner: CliRunner, app_environment: EnvVarsDict):
3434

3535

3636
def test_main(app_environment: EnvVarsDict):
37-
from simcore_service_api_server.main import the_app
37+
from simcore_service_api_server.main import app_factory
3838

39-
assert the_app
39+
the_app = app_factory()
4040
assert isinstance(the_app, FastAPI)

services/autoscaling/src/simcore_service_autoscaling/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ def run():
1919
"""Runs application"""
2020
typer.secho("Sorry, this entrypoint is intentionally disabled. Use instead")
2121
typer.secho(
22-
"$ uvicorn simcore_service_autoscaling.main:the_app",
22+
"$ uvicorn --factory simcore_service_autoscaling.main:app_factory",
2323
fg=typer.colors.BLUE,
2424
)

services/autoscaling/tests/unit/test_main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77

88

99
def test_main_app(app_environment: EnvVarsDict):
10-
from simcore_service_autoscaling.main import the_app, the_settings
10+
from simcore_service_autoscaling.main import app_factory
1111

12-
assert the_app.state.settings == the_settings
12+
app_factory()

services/catalog/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ openapi.json: .env-ignore
1717
@set -o allexport; \
1818
source $<; \
1919
set +o allexport; \
20-
python3 -c "import json; from $(APP_PACKAGE_NAME).main import *; print( json.dumps(the_app.openapi(), indent=2) )" > $@
20+
python3 -c "import json; from $(APP_PACKAGE_NAME).main import *; print( json.dumps(app_factory().openapi(), indent=2) )" > $@
2121

2222
# validates OAS file: $@
2323
$(call validate_openapi_specs,$@)

services/catalog/src/simcore_service_catalog/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def run():
3030
"""Runs application"""
3131
typer.secho("Sorry, this entrypoint is intentionally disabled. Use instead")
3232
typer.secho(
33-
"$ uvicorn simcore_service_catalog.main:the_app",
33+
"$ uvicorn --factory simcore_service_catalog.main:app_factory",
3434
fg=typer.colors.BLUE,
3535
)
3636

services/clusters-keeper/src/simcore_service_clusters_keeper/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ def run():
1919
"""Runs application"""
2020
typer.secho("Sorry, this entrypoint is intentionally disabled. Use instead")
2121
typer.secho(
22-
"$ uvicorn simcore_service_clusters_keeper.main:the_app",
22+
"$ uvicorn --factory simcore_service_clusters_keeper.main:app_factory",
2323
fg=typer.colors.BLUE,
2424
)

services/clusters-keeper/tests/unit/test_main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77

88

99
def test_main_app(app_environment: EnvVarsDict):
10-
from simcore_service_clusters_keeper.main import the_app, the_settings
10+
from simcore_service_clusters_keeper.main import app_factory
1111

12-
assert the_app.state.settings == the_settings
12+
app_factory()

0 commit comments

Comments
 (0)