1616from dstack ._internal .server .services import backends as backends_services
1717from dstack ._internal .server .services import volumes as volumes_services
1818from dstack ._internal .server .services .locking import get_locker
19+ from dstack ._internal .server .services .volumes import switch_volume_status
1920from dstack ._internal .server .utils import sentry_utils
2021from dstack ._internal .utils .common import get_current_datetime , run_async
2122from dstack ._internal .utils .logging import get_logger
@@ -79,8 +80,8 @@ async def _process_submitted_volume(session: AsyncSession, volume_model: VolumeM
7980 volume .name ,
8081 volume .configuration .backend .value ,
8182 )
82- volume_model .status = VolumeStatus .FAILED
8383 volume_model .status_message = "Backend not available"
84+ switch_volume_status (session , volume_model , VolumeStatus .FAILED )
8485 volume_model .last_processed_at = get_current_datetime ()
8586 await session .commit ()
8687 return
@@ -102,18 +103,18 @@ async def _process_submitted_volume(session: AsyncSession, volume_model: VolumeM
102103 )
103104 except BackendError as e :
104105 logger .info ("Failed to create volume %s: %s" , volume_model .name , repr (e ))
105- volume_model .status = VolumeStatus .FAILED
106106 status_message = f"Backend error: { repr (e )} "
107107 if len (e .args ) > 0 :
108108 status_message = str (e .args [0 ])
109109 volume_model .status_message = status_message
110+ switch_volume_status (session , volume_model , VolumeStatus .FAILED )
110111 volume_model .last_processed_at = get_current_datetime ()
111112 await session .commit ()
112113 return
113114 except Exception as e :
114115 logger .exception ("Got exception when creating volume %s" , volume_model .name )
115- volume_model .status = VolumeStatus .FAILED
116116 volume_model .status_message = f"Unexpected error: { repr (e )} "
117+ switch_volume_status (session , volume_model , VolumeStatus .FAILED )
117118 volume_model .last_processed_at = get_current_datetime ()
118119 await session .commit ()
119120 return
@@ -123,6 +124,6 @@ async def _process_submitted_volume(session: AsyncSession, volume_model: VolumeM
123124 # Provisioned volumes marked as active since they become available almost immediately in AWS
124125 # TODO: Consider checking volume state
125126 volume_model .volume_provisioning_data = vpd .json ()
126- volume_model . status = VolumeStatus .ACTIVE
127+ switch_volume_status ( session , volume_model , VolumeStatus .ACTIVE )
127128 volume_model .last_processed_at = get_current_datetime ()
128129 await session .commit ()
0 commit comments