8282 DiskSnapshotsResourceWithStreamingResponse ,
8383 AsyncDiskSnapshotsResourceWithStreamingResponse ,
8484)
85- from ...lib .polling_async import async_poll_until
85+ from ...lib .polling_async import async_poll_until , retry_server_poll_until
8686from ...types .devbox_view import DevboxView
8787from ...types .tunnel_view import TunnelView
8888from ...types .shared_params .mount import Mount
@@ -2042,11 +2042,10 @@ async def await_running(
20422042
20432043 Args:
20442044 id: The ID of the devbox to wait for
2045- config : Optional polling configuration
2045+ polling_config : Optional polling configuration
20462046 extra_headers: Send extra headers
20472047 extra_query: Add additional query parameters to the request
20482048 extra_body: Add additional JSON properties to the request
2049- timeout: Override the client-level default timeout for this request, in seconds
20502049
20512050 Returns:
20522051 The devbox in running state
@@ -2056,13 +2055,13 @@ async def await_running(
20562055 RunloopError: If devbox enters a non-running terminal state
20572056 """
20582057
2059- async def wait_for_devbox_status () -> DevboxView :
2058+ async def wait_for_devbox_status (remaining_timeout_seconds : float ) -> DevboxView :
20602059 # This wait_for_status endpoint polls the devbox status for 10 seconds until it reaches either running or failure.
20612060 # If it's neither, it will throw an error.
20622061 try :
20632062 return await self ._post (
20642063 f"/v1/devboxes/{ id } /wait_for_status" ,
2065- body = {"statuses" : ["running" , "failure" , "shutdown" ]},
2064+ body = {"statuses" : ["running" , "failure" , "shutdown" ], "timeout_seconds" : remaining_timeout_seconds },
20662065 cast_to = DevboxView ,
20672066 )
20682067 except (APITimeoutError , APIStatusError ) as error :
@@ -2077,7 +2076,19 @@ async def wait_for_devbox_status() -> DevboxView:
20772076 def is_done_booting (devbox : DevboxView ) -> bool :
20782077 return devbox .status not in DEVBOX_BOOTING_STATES
20792078
2080- devbox = await async_poll_until (wait_for_devbox_status , is_done_booting , polling_config )
2079+ # calculate the timeout to use. The PollingConfig doesn't
2080+ # match the semantics for server-side polling well, so we
2081+ # instead convert interval*attempts to a total time, and take
2082+ # the minimum total.
2083+ config = polling_config
2084+ if not config :
2085+ config = PollingConfig () # use defaults
2086+
2087+ timeout = config .interval_seconds * config .max_attempts
2088+ if config .timeout_seconds is not None and config .timeout_seconds > 0 :
2089+ timeout = min (config .timeout_seconds , timeout )
2090+
2091+ devbox = await retry_server_poll_until (wait_for_devbox_status , is_done_booting , timeout )
20812092
20822093 if devbox .status != "running" :
20832094 raise RunloopError (f"Devbox entered non-running terminal state: { devbox .status } " )
0 commit comments