Skip to content

Commit 937ed47

Browse files
committed
Get run_termination_reason once
1 parent d61092f commit 937ed47

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

src/dstack/_internal/server/services/jobs/__init__.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -546,15 +546,16 @@ async def _detach_volumes_from_job_instance(
546546

547547
all_detached = True
548548
detached_volumes = []
549+
run_termination_reason = await _get_run_termination_reason(session, job_model)
549550
for volume_model in volume_models:
550551
detached = await _detach_volume_from_job_instance(
551-
session=session,
552552
backend=backend,
553553
job_model=job_model,
554554
jpd=jpd,
555555
job_spec=job_spec,
556556
instance_model=instance_model,
557557
volume_model=volume_model,
558+
run_termination_reason=run_termination_reason,
558559
)
559560
if detached:
560561
detached_volumes.append(volume_model)
@@ -571,13 +572,13 @@ async def _detach_volumes_from_job_instance(
571572

572573

573574
async def _detach_volume_from_job_instance(
574-
session: AsyncSession,
575575
backend: Backend,
576576
job_model: JobModel,
577577
jpd: JobProvisioningData,
578578
job_spec: JobSpec,
579579
instance_model: InstanceModel,
580580
volume_model: VolumeModel,
581+
run_termination_reason: Optional[RunTerminationReason],
581582
) -> bool:
582583
detached = True
583584
volume = volume_model_to_volume(volume_model)
@@ -607,9 +608,10 @@ async def _detach_volume_from_job_instance(
607608
volume=volume,
608609
provisioning_data=jpd,
609610
)
610-
run_termination_reason = await _get_run_termination_reason(session, job_model)
611611
if not detached and _should_force_detach_volume(
612-
job_model, run_termination_reason, job_spec.stop_duration
612+
job_model,
613+
run_termination_reason=run_termination_reason,
614+
stop_duration=job_spec.stop_duration,
613615
):
614616
logger.info(
615617
"Force detaching volume %s from %s",

0 commit comments

Comments
 (0)