Skip to content

Commit

Permalink
@pcrespov review: use a type alias
Browse files Browse the repository at this point in the history
  • Loading branch information
sanderegg committed May 15, 2023
1 parent 09cd55b commit 08022de
Show file tree
Hide file tree
Showing 11 changed files with 17 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@

from distributed.worker import get_worker
from pydantic import BaseModel, Extra, NonNegativeFloat
from servicelib.logging_utils import LogLevelInt
from simcore_service_dask_sidecar.computational_sidecar.docker_utils import (
LogMessageStr,
)
from servicelib.logging_utils import LogLevelInt, LogMessageStr


class BaseTaskEvent(BaseModel, ABC):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@
from models_library.utils.enums import StrAutoEnum
from pydantic import BaseModel, Field
from pydantic.types import NonNegativeFloat
from servicelib.logging_utils import LogLevelInt
from simcore_service_dask_sidecar.computational_sidecar.docker_utils import (
LogMessageStr,
)
from servicelib.logging_utils import LogLevelInt, LogMessageStr


class RabbitEventMessageType(str, Enum):
Expand Down
1 change: 1 addition & 0 deletions packages/service-library/src/servicelib/logging_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ def get_log_record_extra(*, user_id: int | str | None = None) -> LogExtra | None


LogLevelInt: TypeAlias = int
LogMessageStr: TypeAlias = str


def guess_message_log_level(message: str) -> LogLevelInt:
Expand Down
8 changes: 5 additions & 3 deletions packages/service-library/tests/test_logging_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@

import pytest
from pytest import LogCaptureFixture
from servicelib.logging_utils import LogLevelInt, guess_message_log_level, log_decorator
from servicelib.utils import logged_gather
from simcore_service_dask_sidecar.computational_sidecar.docker_utils import (
from servicelib.logging_utils import (
LogLevelInt,
LogMessageStr,
guess_message_log_level,
log_decorator,
)
from servicelib.utils import logged_gather

logger = logging.getLogger(__name__)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,14 @@
from packaging import version
from pydantic import ValidationError
from pydantic.networks import AnyUrl
from servicelib.logging_utils import LogLevelInt
from servicelib.logging_utils import LogLevelInt, LogMessageStr
from settings_library.s3 import S3Settings
from yarl import URL

from ..dask_utils import TaskPublisher, create_dask_worker_logger, publish_event
from ..file_utils import pull_file_from_remote, push_file_to_remote
from ..settings import Settings
from .docker_utils import (
LogMessageStr,
create_container_config,
get_computational_shared_data_mount_point,
get_integration_version,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
Awaitable,
Callable,
Coroutine,
TypeAlias,
cast,
)

Expand All @@ -33,6 +32,7 @@
from servicelib.docker_utils import to_datetime
from servicelib.logging_utils import (
LogLevelInt,
LogMessageStr,
guess_message_log_level,
log_catch,
log_context,
Expand All @@ -56,7 +56,7 @@
from .task_shared_volume import TaskSharedVolumes

logger = create_dask_worker_logger(__name__)
LogPublishingCB = Callable[[str, int], Awaitable[None]]
LogPublishingCB = Callable[[LogMessageStr, LogLevelInt], Awaitable[None]]


async def create_container_config(
Expand Down Expand Up @@ -162,9 +162,6 @@ def _guess_progress_value(progress_match: re.Match[str]) -> float:
return value


LogMessageStr: TypeAlias = str


async def _parse_line(
line: str,
) -> tuple[LogType, datetime.datetime, LogMessageStr, LogLevelInt]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@
from dask_task_models_library.container_tasks.io import TaskCancelEventName
from distributed.worker import get_worker
from distributed.worker_state_machine import TaskState
from servicelib.logging_utils import LogLevelInt
from simcore_service_dask_sidecar.computational_sidecar.docker_utils import (
LogMessageStr,
)
from servicelib.logging_utils import LogLevelInt, LogMessageStr


def create_dask_worker_logger(name: str) -> logging.Logger:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import fsspec
from pydantic import ByteSize, FileUrl, parse_obj_as
from pydantic.networks import AnyUrl
from servicelib.logging_utils import LogLevelInt, LogMessageStr
from settings_library.s3 import S3Settings
from yarl import URL

Expand All @@ -24,7 +25,7 @@
S3_FILE_SYSTEM_SCHEMES: Final = ["s3", "s3a"]


LogPublishingCB = Callable[[str, int], Awaitable[None]]
LogPublishingCB = Callable[[LogMessageStr, LogLevelInt], Awaitable[None]]


def _file_progress_cb(
Expand Down
3 changes: 1 addition & 2 deletions services/dask-sidecar/tests/unit/test_docker_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@
import pytest
from models_library.services_resources import BootMode
from pytest_mock.plugin import MockerFixture
from servicelib.logging_utils import LogLevelInt
from servicelib.logging_utils import LogLevelInt, LogMessageStr
from simcore_service_dask_sidecar.computational_sidecar.docker_utils import (
LogMessageStr,
LogType,
_parse_line,
create_container_config,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@
from fastapi import FastAPI
from models_library.rabbitmq_messages import ProgressType
from servicelib.async_utils import run_sequentially_in_context
from servicelib.logging_utils import LogLevelInt
from servicelib.logging_utils import LogLevelInt, LogMessageStr
from settings_library.basic_types import LogLevel
from simcore_service_dask_sidecar.computational_sidecar.docker_utils import (
LogMessageStr,
)
from simcore_service_dynamic_sidecar.core.rabbitmq import (
post_progress_message,
post_sidecar_log_message,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,9 @@
RabbitMessageBase,
)
from pydantic import NonNegativeFloat
from servicelib.logging_utils import LogLevelInt, log_catch, log_context
from servicelib.logging_utils import LogLevelInt, LogMessageStr, log_catch, log_context
from servicelib.rabbitmq import RabbitMQClient
from servicelib.rabbitmq_utils import wait_till_rabbitmq_responsive
from simcore_service_dask_sidecar.computational_sidecar.docker_utils import (
LogMessageStr,
)

from ..core.settings import ApplicationSettings

Expand Down

0 comments on commit 08022de

Please sign in to comment.