5959from dstack ._internal .server .services .jobs import (
6060 find_job ,
6161 get_job_attached_volumes ,
62+ get_job_provisioning_data ,
6263 get_job_runtime_data ,
6364 job_model_to_job_submission ,
6465)
@@ -373,7 +374,6 @@ async def _process_running_job(session: AsyncSession, job_model: JobModel):
373374 job_model .status = JobStatus .TERMINATING
374375 # job will be terminated and instance will be emptied by process_terminating_jobs
375376 else :
376- # job_model.instance.termination_reason
377377 # No job_model.termination_reason set means ssh connection failed
378378 if job_model .disconnected_at is None :
379379 job_model .disconnected_at = common_utils .get_current_datetime ()
@@ -383,16 +383,22 @@ async def _process_running_job(session: AsyncSession, job_model: JobModel):
383383 fmt (job_model ),
384384 job_submission .age ,
385385 )
386- # TODO: Replace with JobTerminationReason.INSTANCE_UNREACHABLE in 0.20 or
387- # when CLI <= 0.19.8 is no longer supported
388386 if (
389387 job_model .instance is not None
390388 and job_model .instance .termination_reason
391389 == InstanceTerminationReason .NO_BALANCE .value
392390 ):
391+ # if instance was terminated due to no balance, set job termination reason accodingly
393392 job_model .termination_reason = JobTerminationReason .NO_BALANCE
394393 else :
395- job_model .termination_reason = JobTerminationReason .INSTANCE_UNREACHABLE
394+ job_provisioning_data = get_job_provisioning_data (job_model )
395+ # use JobTerminationReason.INSTANCE_UNREACHABLE for on-demand instances only
396+ job_model .termination_reason = (
397+ JobTerminationReason .INSTANCE_UNREACHABLE
398+ if job_provisioning_data
399+ and not job_provisioning_data .instance_type .resources .spot
400+ else JobTerminationReason .INTERRUPTED_BY_NO_CAPACITY
401+ )
396402 job_model .status = JobStatus .TERMINATING
397403 else :
398404 logger .warning (
0 commit comments