Skip to content

Commit 5745718

Browse files
authored
Merge pull request #2 from lalithkota/develop
Fixed run_server method call. Fixed openapi push
2 parents 7e73556 + 12f38f0 commit 5745718

File tree

6 files changed

+22
-7
lines changed

6 files changed

+22
-7
lines changed

.github/workflows/openapi-push.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ jobs:
88
openapi-publish:
99
name: OpenAPI Generate and Publish
1010
runs-on: ubuntu-latest
11+
env:
12+
BRANCH_NAME: ''
13+
OPENAPI_CHANGED: false
14+
STOPLIGHT_PROJECT_TOKEN: ${{ secrets.STOPLIGHT_PROJECT_TOKEN }}
1115
steps:
1216
- uses: actions/checkout@v3
1317
- name: Get branch name (merge)
@@ -41,10 +45,10 @@ jobs:
4145
add: "api-docs/generated/openapi.json"
4246
- name: Setup nodejs
4347
uses: actions/setup-node@v4
44-
if: env.OPENAPI_CHANGED == 'true'
48+
if: env.STOPLIGHT_PROJECT_TOKEN != '' && env.OPENAPI_CHANGED == 'true'
4549
with:
4650
node-version: '18'
4751
- name: Publish to stoplight
48-
if: env.OPENAPI_CHANGED == 'true'
52+
if: env.STOPLIGHT_PROJECT_TOKEN != '' && env.OPENAPI_CHANGED == 'true'
4953
run: |
50-
npx @stoplight/cli@5 push --ci-token ${{ secrets.STOPLIGHT_PROJECT_TOKEN }} --url https://openg2p.stoplight.io --branch ${{ env.BRANCH_NAME }} --directory api-docs/generated
54+
npx @stoplight/cli@5 push --ci-token ${{ env.STOPLIGHT_PROJECT_TOKEN }} --url https://openg2p.stoplight.io --branch ${{ env.BRANCH_NAME }} --directory api-docs/generated

src/openg2p_websub_print_listener/app.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from .config import Settings
44

5-
_config = Settings.get_config()
5+
_config: Settings = Settings.get_config()
66

77
from openg2p_fastapi_common.app import Initializer
88

@@ -27,3 +27,7 @@ def init_app(self):
2727
app = super().init_app()
2828
app.router.redirect_slashes = False
2929
return app
30+
31+
def run_server(self, args):
32+
_config._server_running = True
33+
return super().run_server(args)

src/openg2p_websub_print_listener/config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ class Settings(Settings):
1717
"""
1818
openapi_version: str = __version__
1919

20+
# Internal Variable
21+
_server_running: bool = False
22+
2023
websub_hub_url: str = "http://localhost:9191/hub"
2124
websub_subscribe_lease_seconds: int | None = None
2225
websub_partner_id: str = ""

src/openg2p_websub_print_listener/services/file_store.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ class FileStoreService(BaseService):
1616
def __init__(self, **kw):
1717
super().__init__(**kw)
1818
self.aws_session = aioboto3.Session()
19-
asyncio.run(self.get_or_create_bucket(_config.s3_bucket_name))
19+
if _config._server_running:
20+
asyncio.run(self.get_or_create_bucket(_config.s3_bucket_name))
2021

2122
async def save_file(self, name, data: bytes, mimetype=None, **kw):
2223
file_io = io.BytesIO()

src/openg2p_websub_print_listener/services/template_renderer.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ def __init__(self, **kwargs):
2828

2929
self._unsafe_eval = None
3030

31-
self.check_if_templates_exist()
31+
if _config._server_running:
32+
self.check_if_templates_exist()
3233

3334
def get_unsafe_eval(self):
3435
if not self._unsafe_eval:

tests/test_init.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
from openg2p_websub_print_listener.app import Initializer as WebSubPrintListenerApp
22

3-
WebSubPrintListenerApp()
3+
4+
def test_init():
5+
WebSubPrintListenerApp()

0 commit comments

Comments
 (0)