Skip to content

Commit a105e19

Browse files
authored
Separate orchestrator ASGI launcher into wsgi.py (#60)
1 parent 65cb046 commit a105e19

File tree

5 files changed

+40
-19
lines changed

5 files changed

+40
-19
lines changed

README.md

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -349,32 +349,37 @@ to define the helper functions as locally as possible.
349349

350350
### Main application
351351

352-
The `main.py` can be as simple as shown below, and can be deployed by a
352+
The `wsgi.py` can be as simple as shown below, and can be deployed by a
353353
ASGI server like Uvicorn[^5].
354354

355355
```python
356356
from orchestrator import OrchestratorCore
357-
from orchestrator.cli.main import app as core_cli
358357
from orchestrator.settings import AppSettings
359358

360359
import products
361360
import workflows
362361

363362
app = OrchestratorCore(base_settings=AppSettings())
364363
app.register_graphql()
365-
366-
if __name__ == "__main__":
367-
core_cli()
368364
```
369365

370366
All other orchestrator code is referenced by importing the `products`
371367
and `workflows` modules. The application is started with:
372368

373369
```shell
374-
uvicorn --host localhost --port 8080 main:app
370+
uvicorn --host localhost --port 8080 wsgi:app
371+
```
372+
373+
To use the orchestrator command line interface create a `main.py` like below:
374+
375+
```python
376+
from orchestrator.cli.main import app as core_cli
377+
378+
if __name__ == "__main__":
379+
core_cli()
375380
```
376381

377-
To use the orchestrator command line interface use:
382+
Run the CLI using:
378383

379384
```shell
380385
python main.py --help

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ services:
183183
- ./migrations:/home/orchestrator/migrations
184184
- ./docker:/home/orchestrator/etc
185185
- ./main.py:/home/orchestrator/main.py
186+
- ./wsgi.py:/home/orchestrator/wsgi.py
186187
- ./settings.py:/home/orchestrator/settings.py
187188
- ./graphql_federation.py:/home/orchestrator/graphql_federation.py
188189
- ./utils:/home/orchestrator/utils

docker/orchestrator/entrypoint.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ if [ -f ${CORE_OVERRIDE}/pyproject.toml ]; then
2727
# Run any missing migrations on the database
2828
python main.py db upgrade heads
2929

30-
uvicorn --host 0.0.0.0 --port 8080 $UVICORN_ARGS main:app --reload --proxy-headers \
30+
uvicorn --host 0.0.0.0 --port 8080 $UVICORN_ARGS wsgi:app --reload --proxy-headers \
3131
--reload-dir $CORE_OVERRIDE \
3232
--reload-dir products \
3333
--reload-dir services \
@@ -39,5 +39,5 @@ else
3939
python main.py db upgrade heads
4040

4141
echo "⏭️ Use orchestrator-core as specified in pyproject.toml $(uv pip freeze | grep orchestrator-core)"
42-
uvicorn --host 0.0.0.0 --port 8080 $UVICORN_ARGS main:app --reload --proxy-headers
43-
fi
42+
uvicorn --host 0.0.0.0 --port 8080 $UVICORN_ARGS wsgi:app --reload --proxy-headers
43+
fi

main.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2019-2023 SURF.
1+
# Copyright 2019-2025 SURF, ESnet, GÉANT.
22
# Licensed under the Apache License, Version 2.0 (the "License");
33
# you may not use this file except in compliance with the License.
44
# You may obtain a copy of the License at
@@ -12,16 +12,8 @@
1212
# limitations under the License.
1313

1414

15-
from orchestrator import OrchestratorCore
1615
from orchestrator.cli.main import app as core_cli
17-
from orchestrator.settings import AppSettings
1816

19-
from graphql_federation import CUSTOM_GRAPHQL_MODELS
20-
import products # noqa: F401 Side-effects
21-
import workflows # noqa: F401 Side-effects
22-
23-
app = OrchestratorCore(base_settings=AppSettings())
24-
app.register_graphql(graphql_models=CUSTOM_GRAPHQL_MODELS)
2517

2618
if __name__ == "__main__":
2719
core_cli()

wsgi.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright 2019-2025 SURF, ESnet, GÉANT.
2+
# Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
14+
15+
from orchestrator import OrchestratorCore
16+
from orchestrator.settings import AppSettings
17+
18+
from graphql_federation import CUSTOM_GRAPHQL_MODELS
19+
import products # noqa: F401 Side-effects
20+
import workflows # noqa: F401 Side-effects
21+
22+
app = OrchestratorCore(base_settings=AppSettings())
23+
app.register_graphql(graphql_models=CUSTOM_GRAPHQL_MODELS)

0 commit comments

Comments
 (0)