Skip to content

Commit 43a8b91

Browse files
committed
remove servicelib from dask-task-models
1 parent 71c79d8 commit 43a8b91

File tree

2 files changed

+32
-51
lines changed

2 files changed

+32
-51
lines changed

packages/dask-task-models-library/src/dask_task_models_library/plugins/task_life_cycle_scheduler_plugin.py

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from dask.typing import Key
66
from distributed import Scheduler, SchedulerPlugin
77
from distributed.scheduler import TaskStateState
8-
from servicelib.logging_utils import log_context
98

109
from ..models import TASK_LIFE_CYCLE_EVENT, TaskLifeCycleState
1110

@@ -14,20 +13,12 @@
1413

1514
class TaskLifecycleSchedulerPlugin(SchedulerPlugin):
1615
def __init__(self) -> None:
17-
with log_context(
18-
_logger,
19-
logging.INFO,
20-
"TaskLifecycleSchedulerPlugin init",
21-
):
22-
self.scheduler = None
16+
self.scheduler = None
17+
_logger.info("initialized TaskLifecycleSchedulerPlugin")
2318

2419
async def start(self, scheduler: Scheduler) -> None:
25-
with log_context(
26-
_logger,
27-
logging.INFO,
28-
"TaskLifecycleSchedulerPlugin start",
29-
):
30-
self.scheduler = scheduler # type: ignore[assignment]
20+
self.scheduler = scheduler # type: ignore[assignment]
21+
_logger.info("started TaskLifecycleSchedulerPlugin")
3122

3223
def transition(
3324
self,
@@ -38,19 +29,22 @@ def transition(
3829
stimulus_id: str,
3930
**kwargs: Any,
4031
):
41-
with log_context(
42-
_logger,
43-
logging.INFO,
44-
f"Task {key!r} transition from {start} to {finish} due to {stimulus_id=}",
45-
):
46-
assert self.scheduler # nosec
47-
48-
self.scheduler.log_event(
49-
TASK_LIFE_CYCLE_EVENT.format(key=key),
50-
TaskLifeCycleState.from_scheduler_task_state(
51-
key, kwargs.get("worker"), finish
52-
).model_dump(mode="json"),
53-
)
32+
_logger.debug(
33+
"Task %s transition from %s to %s due to %s",
34+
key,
35+
start,
36+
finish,
37+
stimulus_id,
38+
)
39+
40+
assert self.scheduler # nosec
41+
42+
self.scheduler.log_event(
43+
TASK_LIFE_CYCLE_EVENT.format(key=key),
44+
TaskLifeCycleState.from_scheduler_task_state(
45+
key, kwargs.get("worker"), finish
46+
).model_dump(mode="json"),
47+
)
5448

5549

5650
@click.command()

packages/dask-task-models-library/src/dask_task_models_library/plugins/task_life_cycle_worker_plugin.py

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from distributed import WorkerPlugin
88
from distributed.worker import Worker
99
from distributed.worker_state_machine import TaskStateState
10-
from servicelib.logging_utils import log_context
1110

1211
from ..models import TASK_LIFE_CYCLE_EVENT, TaskLifeCycleState
1312

@@ -16,21 +15,13 @@
1615

1716
class TaskLifecycleWorkerPlugin(WorkerPlugin):
1817
def __init__(self) -> None:
19-
with log_context(
20-
_logger,
21-
logging.INFO,
22-
"TaskLifecycleWorkerPlugin init",
23-
):
24-
self._worker = None
18+
self._worker = None
19+
_logger.info("TaskLifecycleWorkerPlugin initialized")
2520

2621
def setup(self, worker: Worker) -> Awaitable[None]:
2722
async def _() -> None:
28-
with log_context(
29-
_logger,
30-
logging.INFO,
31-
"TaskLifecycleWorkerPlugin start",
32-
):
33-
self._worker = worker # type: ignore[assignment]
23+
self._worker = worker # type: ignore[assignment]
24+
_logger.info("TaskLifecycleWorkerPlugin setup completed")
3425

3526
return _()
3627

@@ -41,18 +32,14 @@ def transition(
4132
finish: TaskStateState,
4233
**kwargs: Any,
4334
):
44-
with log_context(
45-
_logger,
46-
logging.INFO,
47-
f"Task {key!r} transition from {start} to {finish}",
48-
):
49-
assert self._worker # nosec
50-
self._worker.log_event(
51-
TASK_LIFE_CYCLE_EVENT.format(key=key),
52-
TaskLifeCycleState.from_worker_task_state(
53-
key, kwargs.get("worker"), finish
54-
).model_dump(mode="json"),
55-
)
35+
_logger.info("Task '%s' transition from %s to %s", key, start, finish)
36+
assert self._worker # nosec
37+
self._worker.log_event(
38+
TASK_LIFE_CYCLE_EVENT.format(key=key),
39+
TaskLifeCycleState.from_worker_task_state(
40+
key, kwargs.get("worker"), finish
41+
).model_dump(mode="json"),
42+
)
5643

5744

5845
@click.command()

0 commit comments

Comments
 (0)