Skip to content

Commit

Permalink
Maintenance: mypy on dynamic-scheduler (#6122)
Browse files Browse the repository at this point in the history
Co-authored-by: Andrei Neagu <[email protected]>
  • Loading branch information
GitHK and Andrei Neagu authored Jul 30, 2024
1 parent 534139a commit ef70a5c
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 24 deletions.
1 change: 0 additions & 1 deletion .github/workflows/ci-testing-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1119,7 +1119,6 @@ jobs:
run: ./ci/github/unit-testing/dynamic-scheduler.bash install
- name: typecheck
run: ./ci/github/unit-testing/dynamic-scheduler.bash typecheck
continue-on-error: true
- name: test
if: always()
run: ./ci/github/unit-testing/dynamic-scheduler.bash test
Expand Down
4 changes: 4 additions & 0 deletions services/dynamic-scheduler/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ commit_args = --no-verify
asyncio_mode = auto
markers =
testit: "marks test to run during development"

[mypy]
plugins =
pydantic.mypy
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# mypy: disable-error-code=truthy-function
from fastapi import Request
from servicelib.fastapi.dependencies import get_app, get_reverse_url_mapper
from servicelib.rabbitmq import RabbitMQClient, RabbitMQRPCClient
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import logging
from collections.abc import Callable
from typing import Annotated

from fastapi import APIRouter, Depends
from models_library.basic_types import VersionStr

from ..._meta import API_VERSION, PROJECT_NAME
from ...models.schemas.meta import Meta
from ._dependencies import get_reverse_url_mapper

_logger = logging.getLogger(__name__)


router = APIRouter()


Expand All @@ -20,6 +17,6 @@ async def get_service_metadata(
):
return Meta(
name=PROJECT_NAME,
version=API_VERSION,
version=VersionStr(API_VERSION),
docs_url=url_for("swagger_ui_html"),
)
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,21 @@ async def get_service_status(
app: FastAPI, *, node_id: NodeID
) -> NodeGet | DynamicServiceGet | NodeGetIdle:
director_v2_client = DirectorV2Client.get_from_app_state(app)
return await director_v2_client.get_status(node_id)
response: NodeGet | DynamicServiceGet | NodeGetIdle = (
await director_v2_client.get_status(node_id)
)
return response


@router.expose()
async def run_dynamic_service(
app: FastAPI, *, dynamic_service_start: DynamicServiceStart
) -> NodeGet | DynamicServiceGet:
director_v2_client = DirectorV2Client.get_from_app_state(app)
return await director_v2_client.run_dynamic_service(dynamic_service_start)
response: NodeGet | DynamicServiceGet = (
await director_v2_client.run_dynamic_service(dynamic_service_start)
)
return response


@router.expose(
Expand All @@ -45,9 +51,12 @@ async def stop_dynamic_service(
) -> NodeGet | DynamicServiceGet:
director_v2_client = DirectorV2Client.get_from_app_state(app)
settings: ApplicationSettings = app.state.settings
return await director_v2_client.stop_dynamic_service(
node_id=dynamic_service_stop.node_id,
simcore_user_agent=dynamic_service_stop.simcore_user_agent,
save_state=dynamic_service_stop.save_state,
timeout=settings.DYNAMIC_SCHEDULER_STOP_SERVICE_TIMEOUT,
response: NodeGet | DynamicServiceGet = (
await director_v2_client.stop_dynamic_service(
node_id=dynamic_service_stop.node_id,
simcore_user_agent=dynamic_service_stop.simcore_user_agent,
save_state=dynamic_service_stop.save_state,
timeout=settings.DYNAMIC_SCHEDULER_STOP_SERVICE_TIMEOUT,
)
)
return response
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import datetime
from functools import cached_property
from typing import cast

from pydantic import Field, parse_obj_as, validator
from settings_library.application import BaseApplicationSettings
Expand Down Expand Up @@ -51,8 +50,7 @@ def LOG_LEVEL(self): # noqa: N802
@validator("DYNAMIC_SCHEDULER__LOGLEVEL")
@classmethod
def valid_log_level(cls, value: str) -> str:
# NOTE: mypy is not happy without the cast
return cast(str, cls.validate_log_level(value))
return cls.validate_log_level(value)


class ApplicationSettings(_BaseApplicationSettings):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async def get_status(
return DynamicServiceGet.parse_obj(dict_response)
except UnexpectedStatusError as e:
if (
e.response.status_code # pylint:disable=no-member # type: ignore
e.response.status_code # type: ignore[attr-defined] # pylint:disable=no-member
== status.HTTP_404_NOT_FOUND
):
return NodeGetIdle.from_node_id(node_id)
Expand Down Expand Up @@ -83,14 +83,14 @@ async def stop_dynamic_service(
)
except UnexpectedStatusError as e:
if (
e.response.status_code # pylint:disable=no-member # type: ignore
e.response.status_code # type: ignore[attr-defined] # pylint:disable=no-member
== status.HTTP_409_CONFLICT
):
raise ServiceWaitingForManualInterventionError(
node_id=node_id
) from None
if (
e.response.status_code # pylint:disable=no-member # type: ignore
e.response.status_code # type: ignore[attr-defined] # pylint:disable=no-member
== status.HTTP_404_NOT_FOUND
):
raise ServiceWasNotFoundError(node_id=node_id) from None
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import datetime
from typing import cast

from fastapi import FastAPI, status
from httpx import Response, Timeout
Expand Down Expand Up @@ -95,11 +96,14 @@ async def _(
) -> Response:
headers = {X_SIMCORE_USER_AGENT: simcore_user_agent}

return await self.client.delete(
f"dynamic_services/{node_id}?can_save={f'{save_state}'.lower()}",
headers=headers,
timeout=timeout.total_seconds(),
follow_redirects=True,
return cast(
Response,
await self.client.delete(
f"dynamic_services/{node_id}?can_save={f'{save_state}'.lower()}",
headers=headers,
timeout=timeout.total_seconds(),
follow_redirects=True,
),
)

return await _(self)

0 comments on commit ef70a5c

Please sign in to comment.