2929from ..lib .polling import PollingConfig , poll_until
3030from .._base_client import AsyncPaginator , make_request_options
3131from ..lib .polling_async import async_poll_until
32+ from ..lib .cancellation import CancellationToken
3233from .._utils ._validation import ValidationNotification
3334from ..types .blueprint_view import BlueprintView
3435from ..types .blueprint_preview_view import BlueprintPreviewView
4142# Type for request arguments that combine polling config with additional request options
4243class BlueprintRequestArgs (TypedDict , total = False ):
4344 polling_config : PollingConfig | None
45+ cancellation_token : CancellationToken | None
4446 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
4547 # The extra values given here take precedence over values defined on the client or passed to this method.
4648 extra_headers : Headers | None
@@ -280,6 +282,7 @@ def await_build_complete(
280282 id : str ,
281283 * ,
282284 polling_config : PollingConfig | None = None ,
285+ cancellation_token : CancellationToken | None = None ,
283286 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
284287 # The extra values given here take precedence over values defined on the client or passed to this method.
285288 extra_headers : Headers | None = None ,
@@ -292,6 +295,7 @@ def await_build_complete(
292295 Args:
293296 id: The ID of the blueprint to wait for
294297 polling_config: Optional polling configuration
298+ cancellation_token: Token to cancel the wait operation
295299 extra_headers: Send extra headers
296300 extra_query: Add additional query parameters to the request
297301 extra_body: Add additional JSON properties to the request
@@ -302,6 +306,7 @@ def await_build_complete(
302306
303307 Raises:
304308 PollingTimeout: If polling times out before blueprint is built
309+ PollingCancelled: If cancellation_token.cancel() is called
305310 RunloopError: If blueprint enters a non-built terminal state
306311 """
307312
@@ -313,7 +318,12 @@ def retrieve_blueprint() -> BlueprintView:
313318 def is_done_building (blueprint : BlueprintView ) -> bool :
314319 return blueprint .status not in ["queued" , "building" , "provisioning" ]
315320
316- blueprint = poll_until (retrieve_blueprint , is_done_building , polling_config )
321+ blueprint = poll_until (
322+ retrieve_blueprint ,
323+ is_done_building ,
324+ polling_config ,
325+ cancellation_token = cancellation_token ,
326+ )
317327
318328 if blueprint .status != "build_complete" :
319329 raise RunloopError (f"Blueprint entered non-built terminal state: { blueprint .status } " )
@@ -338,6 +348,7 @@ def create_and_await_build_complete(
338348 services : Optional [Iterable [blueprint_create_params .Service ]] | Omit = omit ,
339349 system_setup_commands : Optional [SequenceNotStr [str ]] | Omit = omit ,
340350 polling_config : PollingConfig | None = None ,
351+ cancellation_token : CancellationToken | None = None ,
341352 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
342353 # The extra values given here take precedence over values defined on the client or passed to this method.
343354 extra_headers : Headers | None = None ,
@@ -353,12 +364,14 @@ def create_and_await_build_complete(
353364 Args:
354365 See the `create` method for detailed documentation.
355366 polling_config: Optional polling configuration
367+ cancellation_token: Token to cancel the wait operation
356368
357369 Returns:
358370 The built blueprint
359371
360372 Raises:
361373 PollingTimeout: If polling times out before blueprint is built
374+ PollingCancelled: If cancellation_token.cancel() is called
362375 RunloopError: If blueprint enters a non-built terminal state
363376 """
364377 # Pass all create_args to the underlying create method
@@ -387,6 +400,7 @@ def create_and_await_build_complete(
387400 return self .await_build_complete (
388401 blueprint .id ,
389402 polling_config = polling_config ,
403+ cancellation_token = cancellation_token ,
390404 extra_headers = extra_headers ,
391405 extra_query = extra_query ,
392406 extra_body = extra_body ,
@@ -960,6 +974,7 @@ async def await_build_complete(
960974 id : str ,
961975 * ,
962976 polling_config : PollingConfig | None = None ,
977+ cancellation_token : CancellationToken | None = None ,
963978 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
964979 # The extra values given here take precedence over values defined on the client or passed to this method.
965980 extra_headers : Headers | None = None ,
@@ -972,6 +987,7 @@ async def await_build_complete(
972987 Args:
973988 id: The ID of the blueprint to wait for
974989 polling_config: Optional polling configuration
990+ cancellation_token: Token to cancel the wait operation
975991 extra_headers: Send extra headers
976992 extra_query: Add additional query parameters to the request
977993 extra_body: Add additional JSON properties to the request
@@ -982,6 +998,7 @@ async def await_build_complete(
982998
983999 Raises:
9841000 PollingTimeout: If polling times out before blueprint is built
1001+ PollingCancelled: If cancellation_token.cancel() is called
9851002 RunloopError: If blueprint enters a non-built terminal state
9861003 """
9871004
@@ -993,7 +1010,12 @@ async def retrieve_blueprint() -> BlueprintView:
9931010 def is_done_building (blueprint : BlueprintView ) -> bool :
9941011 return blueprint .status not in ["queued" , "building" , "provisioning" ]
9951012
996- blueprint = await async_poll_until (retrieve_blueprint , is_done_building , polling_config )
1013+ blueprint = await async_poll_until (
1014+ retrieve_blueprint ,
1015+ is_done_building ,
1016+ polling_config ,
1017+ cancellation_token = cancellation_token ,
1018+ )
9971019
9981020 if blueprint .status != "build_complete" :
9991021 raise RunloopError (f"Blueprint entered non-built terminal state: { blueprint .status } " )
@@ -1018,6 +1040,7 @@ async def create_and_await_build_complete(
10181040 services : Optional [Iterable [blueprint_create_params .Service ]] | Omit = omit ,
10191041 system_setup_commands : Optional [SequenceNotStr [str ]] | Omit = omit ,
10201042 polling_config : PollingConfig | None = None ,
1043+ cancellation_token : CancellationToken | None = None ,
10211044 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
10221045 # The extra values given here take precedence over values defined on the client or passed to this method.
10231046 extra_headers : Headers | None = None ,
@@ -1033,12 +1056,14 @@ async def create_and_await_build_complete(
10331056 Args:
10341057 See the `create` method for detailed documentation.
10351058 polling_config: Optional polling configuration
1059+ cancellation_token: Token to cancel the wait operation
10361060
10371061 Returns:
10381062 The built blueprint
10391063
10401064 Raises:
10411065 PollingTimeout: If polling times out before blueprint is built
1066+ PollingCancelled: If cancellation_token.cancel() is called
10421067 RunloopError: If blueprint enters a non-built terminal state
10431068 """
10441069 # Pass all create_args to the underlying create method
@@ -1067,6 +1092,7 @@ async def create_and_await_build_complete(
10671092 return await self .await_build_complete (
10681093 blueprint .id ,
10691094 polling_config = polling_config ,
1095+ cancellation_token = cancellation_token ,
10701096 extra_headers = extra_headers ,
10711097 extra_query = extra_query ,
10721098 extra_body = extra_body ,
0 commit comments