-
Notifications
You must be signed in to change notification settings - Fork 32
✨ adds entry point to dynamic-scheduler exposing the current running services
#7454
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mergify
merged 6 commits into
ITISFoundation:master
from
GitHK:pr-osparc-expose-list-service-for-ops
Apr 1, 2025
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ae6618d
added endpoint for ops
e859ad0
services/dynamic-scheduler version: 1.0.0 → 1.1.0
3d866c0
Merge remote-tracking branch 'upstream/master' into pr-osparc-expose-…
74f32ad
updated specs
dcdce19
Merge remote-tracking branch 'upstream/master' into pr-osparc-expose-…
576de78
Merge branch 'master' into pr-osparc-expose-list-service-for-ops
mergify[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
services/dynamic-scheduler/src/simcore_service_dynamic_scheduler/api/rest/_ops.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| from typing import Annotated | ||
|
|
||
| from fastapi import APIRouter, Depends, FastAPI | ||
| from models_library.api_schemas_directorv2.dynamic_services import ( | ||
| DynamicServiceGet, | ||
| ) | ||
|
|
||
| from ...services import scheduler_interface | ||
| from ._dependencies import ( | ||
| get_app, | ||
| ) | ||
|
|
||
| router = APIRouter() | ||
|
|
||
|
|
||
| @router.get("/ops/running-services") | ||
| async def running_services( | ||
| app: Annotated[FastAPI, Depends(get_app)], | ||
| ) -> list[DynamicServiceGet]: | ||
GitHK marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| """returns all running dynamic services. Used by ops internall to determine | ||
| when it is safe to shutdown the platform""" | ||
| return await scheduler_interface.list_tracked_dynamic_services( | ||
| app, user_id=None, project_id=None | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
services/dynamic-scheduler/tests/unit/api_rest/test_api_rest__ops.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| # pylint:disable=redefined-outer-name | ||
| # pylint:disable=unused-argument | ||
| import json | ||
| from collections.abc import Iterator | ||
|
|
||
| import pytest | ||
| import respx | ||
| from fastapi import status | ||
| from fastapi.encoders import jsonable_encoder | ||
| from httpx import AsyncClient | ||
| from models_library.api_schemas_directorv2.dynamic_services import ( | ||
| DynamicServiceGet, | ||
| ) | ||
| from pydantic import TypeAdapter | ||
| from simcore_service_dynamic_scheduler._meta import API_VTAG | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def mock_director_v2_service( | ||
| running_services: list[DynamicServiceGet], | ||
| ) -> Iterator[None]: | ||
| with respx.mock( | ||
| base_url="http://director-v2:8000/v2", | ||
| assert_all_called=False, | ||
| assert_all_mocked=True, # IMPORTANT: KEEP always True! | ||
| ) as mock: | ||
| mock.get("/dynamic_services").respond( | ||
| status.HTTP_200_OK, | ||
| text=json.dumps(jsonable_encoder(running_services)), | ||
| ) | ||
|
|
||
| yield None | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "running_services", | ||
| [ | ||
| DynamicServiceGet.model_json_schema()["examples"], | ||
| [], | ||
| ], | ||
| ) | ||
| async def test_running_services(mock_director_v2_service: None, client: AsyncClient): | ||
| response = await client.get(f"/{API_VTAG}/ops/running-services") | ||
| assert response.status_code == status.HTTP_200_OK | ||
| assert isinstance( | ||
| TypeAdapter(list[DynamicServiceGet]).validate_python(response.json()), list | ||
pcrespov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.