Skip to content

Commit 7575aa1

Browse files
author
Andrei Neagu
committed
added cleanup for director-v2's scheduler
1 parent b25e711 commit 7575aa1

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

services/director-v2/src/simcore_service_director_v2/core/application.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
dynamic_services,
3535
dynamic_sidecar,
3636
instrumentation,
37+
long_running_tasks,
3738
notifier,
3839
rabbitmq,
3940
redis,
@@ -220,6 +221,7 @@ def create_app( # noqa: C901, PLR0912
220221
dynamic_sidecar.setup(app)
221222
socketio.setup(app)
222223
notifier.setup(app)
224+
long_running_tasks.setup(app)
223225

224226
if (
225227
settings.DIRECTOR_V2_COMPUTATIONAL_BACKEND.COMPUTATIONAL_BACKEND_DASK_CLIENT_ENABLED

services/director-v2/src/simcore_service_director_v2/modules/dynamic_sidecar/scheduler/_core/_events_utils.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
)
3636
from servicelib.utils import limited_gather, logged_gather
3737
from simcore_postgres_database.models.comp_tasks import NodeClass
38+
from simcore_service_director_v2.modules.long_running_tasks import (
39+
get_client_long_running_manager,
40+
)
3841
from tenacity import RetryError, TryAgain
3942
from tenacity.asyncio import AsyncRetrying
4043
from tenacity.before_sleep import before_sleep_log
@@ -289,6 +292,16 @@ async def service_remove_sidecar_proxy_docker_networks_and_volumes(
289292
message="finished removing resources", percent=ProgressPercent(1)
290293
)
291294

295+
await _cleanup_long_running_tasks(app, scheduler_data.node_uuid)
296+
297+
298+
async def _cleanup_long_running_tasks(app: FastAPI, node_id: NodeID) -> None:
299+
clinet_long_running_manager = get_client_long_running_manager(app)
300+
301+
await clinet_long_running_manager.cleanup_store(
302+
clinet_long_running_manager.get_sidecar_namespace(node_id)
303+
)
304+
292305

293306
async def attempt_pod_removal_and_data_saving(
294307
app: FastAPI, scheduler_data: SchedulerData
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from fastapi import FastAPI
2+
from servicelib.long_running_tasks.client_long_running_manager import (
3+
ClientLongRunningManager,
4+
)
5+
6+
7+
def setup(app: FastAPI):
8+
async def _on_startup() -> None:
9+
client_long_running_manager = app.state.client_long_running_manager = (
10+
ClientLongRunningManager(redis_settings=app.state.settings.REDIS)
11+
)
12+
await client_long_running_manager.setup()
13+
14+
async def _on_shutdown() -> None:
15+
client_long_running_manager: ClientLongRunningManager = (
16+
app.state.client_long_running_manager
17+
)
18+
await client_long_running_manager.shutdown()
19+
20+
app.add_event_handler("startup", _on_startup)
21+
app.add_event_handler("shutdown", _on_shutdown)
22+
23+
24+
def get_client_long_running_manager(app: FastAPI) -> ClientLongRunningManager:
25+
assert isinstance(
26+
app.state.client_long_running_manager, ClientLongRunningManager
27+
) # nosec
28+
return app.state.client_long_running_manager

0 commit comments

Comments
 (0)