@@ -1564,7 +1564,10 @@ def create(
15641564 )
15651565 dataset_resource_name = self ._wait_for_operation (
15661566 operation = create_prompt_dataset_operation ,
1567- timeout = config .timeout if config else 90 ,
1567+ timeout = config .timeout if config and config .timeout else 90 ,
1568+ max_wait_time = (
1569+ config .max_wait_time if config and config .max_wait_time else 60
1570+ ),
15681571 )
15691572 dataset_id = dataset_resource_name .split ("/" )[- 1 ]
15701573
@@ -1636,7 +1639,10 @@ def create_version(
16361639 )
16371640 dataset_resource_name = self ._wait_for_operation (
16381641 operation = create_prompt_dataset_operation ,
1639- timeout = config .timeout if config else 90 ,
1642+ timeout = config .timeout if config and config .timeout else 90 ,
1643+ max_wait_time = (
1644+ config .max_wait_time if config and config .max_wait_time else 60
1645+ ),
16401646 )
16411647 dataset_id = dataset_resource_name .split ("/" )[- 1 ]
16421648
@@ -1660,7 +1666,10 @@ def create_version(
16601666 )
16611667 dataset_version_resource_name = self ._wait_for_operation (
16621668 operation = create_dataset_version_operation ,
1663- timeout = config .timeout if config else 90 ,
1669+ timeout = config .timeout if config and config .timeout else 90 ,
1670+ max_wait_time = (
1671+ config .max_wait_time if config and config .max_wait_time else 60
1672+ ),
16641673 )
16651674
16661675 # Step 4: Get the dataset version resource and return it with the prompt
@@ -1679,12 +1688,14 @@ def _wait_for_operation(
16791688 self ,
16801689 operation : types .DatasetOperation ,
16811690 timeout : int ,
1691+ max_wait_time : int = 60 ,
16821692 ) -> str :
16831693 """Waits for a dataset operation to complete.
16841694
16851695 Args:
16861696 operation: The dataset operation to wait for.
16871697 timeout: The maximum time to wait for the operation to complete.
1698+ max_wait_time: The maximum interval between polling requests in seconds.
16881699
16891700 Returns:
16901701 The name of the Dataset resource from the operation result.
@@ -1706,7 +1717,6 @@ def _wait_for_operation(
17061717 start_time = time .time ()
17071718 sleep_duration = 5
17081719 wait_multiplier = 2
1709- max_wait_time = 60
17101720 previous_time = time .time ()
17111721
17121722 while not done :
@@ -1923,6 +1933,7 @@ def _wait_for_project_operation(
19231933 self ,
19241934 operation : genai_types .ProjectOperation ,
19251935 timeout : int ,
1936+ max_wait_time : int = 60 ,
19261937 ) -> None :
19271938 """Waits for a dataset deletion operation to complete.
19281939
@@ -1931,6 +1942,7 @@ def _wait_for_project_operation(
19311942 Args:
19321943 operation: The project operation to wait for.
19331944 timeout: The maximum time to wait for the operation to complete.
1945+ max_wait_time: The maximum interval between polling requests in seconds.
19341946 Raises:
19351947 TimeoutError: If the operation does not complete within the timeout.
19361948 ValueError: If the operation fails.
@@ -1940,7 +1952,6 @@ def _wait_for_project_operation(
19401952 start_time = time .time ()
19411953 sleep_duration = 5
19421954 wait_multiplier = 2
1943- max_wait_time = 60
19441955 previous_time = time .time ()
19451956 while not done :
19461957 if (time .time () - start_time ) > timeout :
@@ -1985,7 +1996,11 @@ def delete(
19851996 config = config ,
19861997 )
19871998 self ._wait_for_project_operation (
1988- operation = delete_prompt_operation , timeout = config .timeout if config else 90
1999+ operation = delete_prompt_operation ,
2000+ timeout = config .timeout if config and config .timeout else 90 ,
2001+ max_wait_time = (
2002+ config .max_wait_time if config and config .max_wait_time else 60
2003+ ),
19892004 )
19902005 logger .info (f"Deleted prompt with id: { prompt_id } " )
19912006
@@ -2013,7 +2028,11 @@ def delete_version(
20132028 )
20142029
20152030 self ._wait_for_project_operation (
2016- operation = delete_version_operation , timeout = config .timeout if config else 90
2031+ operation = delete_version_operation ,
2032+ timeout = config .timeout if config and config .timeout else 90 ,
2033+ max_wait_time = (
2034+ config .max_wait_time if config and config .max_wait_time else 60
2035+ ),
20172036 )
20182037 logger .info (
20192038 f"Deleted prompt version { version_id } from prompt with id: { prompt_id } "
@@ -2040,10 +2059,14 @@ def restore_version(
20402059 restore_prompt_operation = self ._restore_version (
20412060 dataset_id = prompt_id ,
20422061 version_id = version_id ,
2062+ config = config ,
20432063 )
20442064 self ._wait_for_project_operation (
20452065 operation = restore_prompt_operation ,
2046- timeout = 90 ,
2066+ timeout = config .timeout if config and config .timeout else 90 ,
2067+ max_wait_time = (
2068+ config .max_wait_time if config and config .max_wait_time else 60
2069+ ),
20472070 )
20482071 dataset_version_resource = self ._get_dataset_version_resource (
20492072 dataset_id = prompt_id ,
@@ -2400,7 +2423,10 @@ def update(
24002423 )
24012424 dataset_version_resource_name = self ._wait_for_operation (
24022425 operation = create_dataset_version_operation ,
2403- timeout = config .timeout if config else 90 ,
2426+ timeout = config .timeout if config and config .timeout else 90 ,
2427+ max_wait_time = (
2428+ config .max_wait_time if config and config .max_wait_time else 60
2429+ ),
24042430 )
24052431 dataset_version_id = dataset_version_resource_name .split ("/" )[- 1 ]
24062432
@@ -3558,7 +3584,10 @@ async def create(
35583584 )
35593585 dataset_resource_name = await self ._wait_for_operation (
35603586 operation = create_prompt_dataset_operation ,
3561- timeout = config .timeout if config else 90 ,
3587+ timeout = config .timeout if config and config .timeout else 90 ,
3588+ max_wait_time = (
3589+ config .max_wait_time if config and config .max_wait_time else 60
3590+ ),
35623591 )
35633592 dataset_id = dataset_resource_name .split ("/" )[- 1 ]
35643593
@@ -3629,7 +3658,10 @@ async def create_version(
36293658 )
36303659 dataset_resource_name = await self ._wait_for_operation (
36313660 operation = create_prompt_dataset_operation ,
3632- timeout = config .timeout if config else 90 ,
3661+ timeout = config .timeout if config and config .timeout else 90 ,
3662+ max_wait_time = (
3663+ config .max_wait_time if config and config .max_wait_time else 60
3664+ ),
36333665 )
36343666 dataset_id = dataset_resource_name .split ("/" )[- 1 ]
36353667
@@ -3653,7 +3685,10 @@ async def create_version(
36533685 )
36543686 dataset_version_resource_name = await self ._wait_for_operation (
36553687 operation = create_dataset_version_operation ,
3656- timeout = config .timeout if config else 90 ,
3688+ timeout = config .timeout if config and config .timeout else 90 ,
3689+ max_wait_time = (
3690+ config .max_wait_time if config and config .max_wait_time else 60
3691+ ),
36573692 )
36583693
36593694 # Step 4: Get the dataset version resource and return it with the prompt
@@ -3740,7 +3775,10 @@ async def update(
37403775 )
37413776 dataset_version_resource_name = await self ._wait_for_operation (
37423777 operation = create_dataset_version_operation ,
3743- timeout = config .timeout if config else 90 ,
3778+ timeout = config .timeout if config and config .timeout else 90 ,
3779+ max_wait_time = (
3780+ config .max_wait_time if config and config .max_wait_time else 60
3781+ ),
37443782 )
37453783 dataset_version_id = dataset_version_resource_name .split ("/" )[- 1 ]
37463784
@@ -3760,12 +3798,14 @@ async def _wait_for_operation(
37603798 self ,
37613799 operation : types .DatasetOperation ,
37623800 timeout : int ,
3801+ max_wait_time : int = 60 ,
37633802 ) -> str :
37643803 """Waits for a dataset operation to complete.
37653804
37663805 Args:
37673806 operation: The dataset operation to wait for.
37683807 timeout: The maximum time to wait for the operation to complete.
3808+ max_wait_time: The maximum interval between polling requests in seconds.
37693809
37703810 Returns:
37713811 The name of the Dataset resource from the operation result.
@@ -3787,7 +3827,6 @@ async def _wait_for_operation(
37873827 start_time = time .time ()
37883828 sleep_duration = 5
37893829 wait_multiplier = 2
3790- max_wait_time = 60
37913830 previous_time = time .time ()
37923831
37933832 while not done :
@@ -3885,6 +3924,7 @@ async def _wait_for_project_operation(
38853924 self ,
38863925 operation : genai_types .ProjectOperation ,
38873926 timeout : int ,
3927+ max_wait_time : int = 60 ,
38883928 ) -> None :
38893929 """Waits for a dataset deletion operation to complete.
38903930
@@ -3893,6 +3933,7 @@ async def _wait_for_project_operation(
38933933 Args:
38943934 operation: The project operation to wait for.
38953935 timeout: The maximum time to wait for the operation to complete.
3936+ max_wait_time: The maximum interval between polling requests in seconds.
38963937 Raises:
38973938 TimeoutError: If the operation does not complete within the timeout.
38983939 ValueError: If the operation fails.
@@ -3902,7 +3943,6 @@ async def _wait_for_project_operation(
39023943 start_time = time .time ()
39033944 sleep_duration = 5
39043945 wait_multiplier = 2
3905- max_wait_time = 60
39063946 previous_time = time .time ()
39073947 while not done :
39083948 if (time .time () - start_time ) > timeout :
@@ -3947,7 +3987,11 @@ async def delete(
39473987 config = config ,
39483988 )
39493989 await self ._wait_for_project_operation (
3950- operation = delete_prompt_operation , timeout = config .timeout if config else 90
3990+ operation = delete_prompt_operation ,
3991+ timeout = config .timeout if config and config .timeout else 90 ,
3992+ max_wait_time = (
3993+ config .max_wait_time if config and config .max_wait_time else 60
3994+ ),
39513995 )
39523996 logger .info (f"Deleted prompt with id: { prompt_id } " )
39533997
@@ -3975,7 +4019,11 @@ async def delete_version(
39754019 )
39764020
39774021 await self ._wait_for_project_operation (
3978- operation = delete_version_operation , timeout = config .timeout if config else 90
4022+ operation = delete_version_operation ,
4023+ timeout = config .timeout if config and config .timeout else 90 ,
4024+ max_wait_time = (
4025+ config .max_wait_time if config and config .max_wait_time else 60
4026+ ),
39794027 )
39804028 logger .info (
39814029 f"Deleted prompt version { version_id } from prompt with id: { prompt_id } "
@@ -4111,10 +4159,14 @@ async def restore_version(
41114159 restore_prompt_operation = await self ._restore_version (
41124160 dataset_id = prompt_id ,
41134161 version_id = version_id ,
4162+ config = config ,
41144163 )
41154164 await self ._wait_for_project_operation (
41164165 operation = restore_prompt_operation ,
4117- timeout = 90 ,
4166+ timeout = config .timeout if config and config .timeout else 90 ,
4167+ max_wait_time = (
4168+ config .max_wait_time if config and config .max_wait_time else 60
4169+ ),
41184170 )
41194171 dataset_version_resource = await self ._get_dataset_version_resource (
41204172 dataset_id = prompt_id ,
0 commit comments