7272 AsyncDiskSnapshotsCursorIDPage ,
7373)
7474from ..._exceptions import RunloopError , APIStatusError , APITimeoutError
75- from ...lib .polling import PollingConfig , poll_until
75+ from ...lib .polling import PollingConfig , poll_until , retry_server_poll_until as sync_retry_server_poll_until
7676from ..._base_client import AsyncPaginator , make_request_options
7777from .disk_snapshots import (
7878 DiskSnapshotsResource ,
8282 DiskSnapshotsResourceWithStreamingResponse ,
8383 AsyncDiskSnapshotsResourceWithStreamingResponse ,
8484)
85- from ...lib .polling_async import async_poll_until , retry_server_poll_until
85+ from ...lib .polling_async import async_poll_until , async_retry_server_poll_until
8686from ...types .devbox_view import DevboxView
8787from ...types .tunnel_view import TunnelView
8888from ...types .shared_params .mount import Mount
@@ -397,30 +397,31 @@ def await_running(
397397 RunloopError: If devbox enters a non-running terminal state
398398 """
399399
400- def wait_for_devbox_status () -> DevboxView :
401- # This wait_for_status endpoint polls the devbox status for 10 seconds until it reaches either running or failure.
402- # If it's neither, it will throw an error.
403- return self ._post (
404- f"/v1/devboxes/{ id } /wait_for_status" ,
405- body = {"statuses" : ["running" , "failure" , "shutdown" ]},
406- cast_to = DevboxView ,
407- )
408-
409- def handle_timeout_error (error : Exception ) -> DevboxView :
410- # Handle timeout errors by returning current devbox state to continue polling
411- if isinstance (error , APITimeoutError ) or (
412- isinstance (error , APIStatusError ) and error .response .status_code == 408
413- ):
414- # Return a placeholder result to continue polling
415- return placeholder_devbox_view (id )
416-
417- # Re-raise other errors to stop polling
418- raise error
400+ def wait_for_devbox_status (remaining_timeout_seconds : float ) -> DevboxView :
401+ try :
402+ return self ._post (
403+ f"/v1/devboxes/{ id } /wait_for_status" ,
404+ body = {"statuses" : ["running" , "failure" , "shutdown" ], "timeout_seconds" : remaining_timeout_seconds },
405+ cast_to = DevboxView ,
406+ options = {"max_retries" : 0 },
407+ )
408+ except (APITimeoutError , APIStatusError ) as error :
409+ if isinstance (error , APITimeoutError ) or error .response .status_code == 408 :
410+ return placeholder_devbox_view (id )
411+ raise
419412
420413 def is_done_booting (devbox : DevboxView ) -> bool :
421414 return devbox .status not in DEVBOX_BOOTING_STATES
422415
423- devbox = poll_until (wait_for_devbox_status , is_done_booting , polling_config , handle_timeout_error )
416+ config = polling_config
417+ if not config :
418+ config = PollingConfig ()
419+
420+ timeout = config .interval_seconds * config .max_attempts
421+ if config .timeout_seconds is not None and config .timeout_seconds > 0 :
422+ timeout = min (config .timeout_seconds , timeout )
423+
424+ devbox = sync_retry_server_poll_until (wait_for_devbox_status , is_done_booting , timeout )
424425
425426 if devbox .status != "running" :
426427 raise RunloopError (f"Devbox entered non-running terminal state: { devbox .status } " )
@@ -452,6 +453,7 @@ def wait_for_devbox_status() -> DevboxView:
452453 f"/v1/devboxes/{ id } /wait_for_status" ,
453454 body = {"statuses" : list (DEVBOX_TERMINAL_STATES )},
454455 cast_to = DevboxView ,
456+ options = {"max_retries" : 0 },
455457 )
456458
457459 def handle_timeout_error (error : Exception ) -> DevboxView :
@@ -2063,6 +2065,7 @@ async def wait_for_devbox_status(remaining_timeout_seconds: float) -> DevboxView
20632065 f"/v1/devboxes/{ id } /wait_for_status" ,
20642066 body = {"statuses" : ["running" , "failure" , "shutdown" ], "timeout_seconds" : remaining_timeout_seconds },
20652067 cast_to = DevboxView ,
2068+ options = {"max_retries" : 0 },
20662069 )
20672070 except (APITimeoutError , APIStatusError ) as error :
20682071 # Handle timeout errors by returning current devbox state to continue polling
@@ -2088,7 +2091,7 @@ def is_done_booting(devbox: DevboxView) -> bool:
20882091 if config .timeout_seconds is not None and config .timeout_seconds > 0 :
20892092 timeout = min (config .timeout_seconds , timeout )
20902093
2091- devbox = await retry_server_poll_until (wait_for_devbox_status , is_done_booting , timeout )
2094+ devbox = await async_retry_server_poll_until (wait_for_devbox_status , is_done_booting , timeout )
20922095
20932096 if devbox .status != "running" :
20942097 raise RunloopError (f"Devbox entered non-running terminal state: { devbox .status } " )
@@ -2121,6 +2124,7 @@ async def wait_for_devbox_status() -> DevboxView:
21212124 f"/v1/devboxes/{ id } /wait_for_status" ,
21222125 body = {"statuses" : list (DEVBOX_TERMINAL_STATES )},
21232126 cast_to = DevboxView ,
2127+ options = {"max_retries" : 0 },
21242128 )
21252129 except (APITimeoutError , APIStatusError ) as error :
21262130 if isinstance (error , APITimeoutError ) or error .response .status_code == 408 :
0 commit comments