@@ -1564,7 +1564,12 @@ 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 is not None else 90 ,
1568+ max_wait_time = (
1569+ config .max_wait_time
1570+ if config and config .max_wait_time is not None
1571+ else 60
1572+ ),
15681573 )
15691574 dataset_id = dataset_resource_name .split ("/" )[- 1 ]
15701575
@@ -1636,7 +1641,12 @@ def create_version(
16361641 )
16371642 dataset_resource_name = self ._wait_for_operation (
16381643 operation = create_prompt_dataset_operation ,
1639- timeout = config .timeout if config else 90 ,
1644+ timeout = config .timeout if config and config .timeout is not None else 90 ,
1645+ max_wait_time = (
1646+ config .max_wait_time
1647+ if config and config .max_wait_time is not None
1648+ else 60
1649+ ),
16401650 )
16411651 dataset_id = dataset_resource_name .split ("/" )[- 1 ]
16421652
@@ -1660,7 +1670,12 @@ def create_version(
16601670 )
16611671 dataset_version_resource_name = self ._wait_for_operation (
16621672 operation = create_dataset_version_operation ,
1663- timeout = config .timeout if config else 90 ,
1673+ timeout = config .timeout if config and config .timeout is not None else 90 ,
1674+ max_wait_time = (
1675+ config .max_wait_time
1676+ if config and config .max_wait_time is not None
1677+ else 60
1678+ ),
16641679 )
16651680
16661681 # Step 4: Get the dataset version resource and return it with the prompt
@@ -1679,12 +1694,14 @@ def _wait_for_operation(
16791694 self ,
16801695 operation : types .DatasetOperation ,
16811696 timeout : int ,
1697+ max_wait_time : int = 60 ,
16821698 ) -> str :
16831699 """Waits for a dataset operation to complete.
16841700
16851701 Args:
16861702 operation: The dataset operation to wait for.
16871703 timeout: The maximum time to wait for the operation to complete.
1704+ max_wait_time: The maximum interval between polling requests in seconds.
16881705
16891706 Returns:
16901707 The name of the Dataset resource from the operation result.
@@ -1706,7 +1723,6 @@ def _wait_for_operation(
17061723 start_time = time .time ()
17071724 sleep_duration = 5
17081725 wait_multiplier = 2
1709- max_wait_time = 60
17101726 previous_time = time .time ()
17111727
17121728 while not done :
@@ -1923,6 +1939,7 @@ def _wait_for_project_operation(
19231939 self ,
19241940 operation : genai_types .ProjectOperation ,
19251941 timeout : int ,
1942+ max_wait_time : int = 60 ,
19261943 ) -> None :
19271944 """Waits for a dataset deletion operation to complete.
19281945
@@ -1931,6 +1948,7 @@ def _wait_for_project_operation(
19311948 Args:
19321949 operation: The project operation to wait for.
19331950 timeout: The maximum time to wait for the operation to complete.
1951+ max_wait_time: The maximum interval between polling requests in seconds.
19341952 Raises:
19351953 TimeoutError: If the operation does not complete within the timeout.
19361954 ValueError: If the operation fails.
@@ -1940,7 +1958,6 @@ def _wait_for_project_operation(
19401958 start_time = time .time ()
19411959 sleep_duration = 5
19421960 wait_multiplier = 2
1943- max_wait_time = 60
19441961 previous_time = time .time ()
19451962 while not done :
19461963 if (time .time () - start_time ) > timeout :
@@ -1985,7 +2002,13 @@ def delete(
19852002 config = config ,
19862003 )
19872004 self ._wait_for_project_operation (
1988- operation = delete_prompt_operation , timeout = config .timeout if config else 90
2005+ operation = delete_prompt_operation ,
2006+ timeout = config .timeout if config and config .timeout is not None else 90 ,
2007+ max_wait_time = (
2008+ config .max_wait_time
2009+ if config and config .max_wait_time is not None
2010+ else 60
2011+ ),
19892012 )
19902013 logger .info (f"Deleted prompt with id: { prompt_id } " )
19912014
@@ -2013,7 +2036,13 @@ def delete_version(
20132036 )
20142037
20152038 self ._wait_for_project_operation (
2016- operation = delete_version_operation , timeout = config .timeout if config else 90
2039+ operation = delete_version_operation ,
2040+ timeout = config .timeout if config and config .timeout is not None else 90 ,
2041+ max_wait_time = (
2042+ config .max_wait_time
2043+ if config and config .max_wait_time is not None
2044+ else 60
2045+ ),
20172046 )
20182047 logger .info (
20192048 f"Deleted prompt version { version_id } from prompt with id: { prompt_id } "
@@ -2040,10 +2069,16 @@ def restore_version(
20402069 restore_prompt_operation = self ._restore_version (
20412070 dataset_id = prompt_id ,
20422071 version_id = version_id ,
2072+ config = config ,
20432073 )
20442074 self ._wait_for_project_operation (
20452075 operation = restore_prompt_operation ,
2046- timeout = 90 ,
2076+ timeout = config .timeout if config and config .timeout is not None else 90 ,
2077+ max_wait_time = (
2078+ config .max_wait_time
2079+ if config and config .max_wait_time is not None
2080+ else 60
2081+ ),
20472082 )
20482083 dataset_version_resource = self ._get_dataset_version_resource (
20492084 dataset_id = prompt_id ,
@@ -2400,7 +2435,12 @@ def update(
24002435 )
24012436 dataset_version_resource_name = self ._wait_for_operation (
24022437 operation = create_dataset_version_operation ,
2403- timeout = config .timeout if config else 90 ,
2438+ timeout = config .timeout if config and config .timeout is not None else 90 ,
2439+ max_wait_time = (
2440+ config .max_wait_time
2441+ if config and config .max_wait_time is not None
2442+ else 60
2443+ ),
24042444 )
24052445 dataset_version_id = dataset_version_resource_name .split ("/" )[- 1 ]
24062446
@@ -3558,7 +3598,12 @@ async def create(
35583598 )
35593599 dataset_resource_name = await self ._wait_for_operation (
35603600 operation = create_prompt_dataset_operation ,
3561- timeout = config .timeout if config else 90 ,
3601+ timeout = config .timeout if config and config .timeout is not None else 90 ,
3602+ max_wait_time = (
3603+ config .max_wait_time
3604+ if config and config .max_wait_time is not None
3605+ else 60
3606+ ),
35623607 )
35633608 dataset_id = dataset_resource_name .split ("/" )[- 1 ]
35643609
@@ -3629,7 +3674,12 @@ async def create_version(
36293674 )
36303675 dataset_resource_name = await self ._wait_for_operation (
36313676 operation = create_prompt_dataset_operation ,
3632- timeout = config .timeout if config else 90 ,
3677+ timeout = config .timeout if config and config .timeout is not None else 90 ,
3678+ max_wait_time = (
3679+ config .max_wait_time
3680+ if config and config .max_wait_time is not None
3681+ else 60
3682+ ),
36333683 )
36343684 dataset_id = dataset_resource_name .split ("/" )[- 1 ]
36353685
@@ -3653,7 +3703,12 @@ async def create_version(
36533703 )
36543704 dataset_version_resource_name = await self ._wait_for_operation (
36553705 operation = create_dataset_version_operation ,
3656- timeout = config .timeout if config else 90 ,
3706+ timeout = config .timeout if config and config .timeout is not None else 90 ,
3707+ max_wait_time = (
3708+ config .max_wait_time
3709+ if config and config .max_wait_time is not None
3710+ else 60
3711+ ),
36573712 )
36583713
36593714 # Step 4: Get the dataset version resource and return it with the prompt
@@ -3740,7 +3795,12 @@ async def update(
37403795 )
37413796 dataset_version_resource_name = await self ._wait_for_operation (
37423797 operation = create_dataset_version_operation ,
3743- timeout = config .timeout if config else 90 ,
3798+ timeout = config .timeout if config and config .timeout is not None else 90 ,
3799+ max_wait_time = (
3800+ config .max_wait_time
3801+ if config and config .max_wait_time is not None
3802+ else 60
3803+ ),
37443804 )
37453805 dataset_version_id = dataset_version_resource_name .split ("/" )[- 1 ]
37463806
@@ -3760,12 +3820,14 @@ async def _wait_for_operation(
37603820 self ,
37613821 operation : types .DatasetOperation ,
37623822 timeout : int ,
3823+ max_wait_time : int = 60 ,
37633824 ) -> str :
37643825 """Waits for a dataset operation to complete.
37653826
37663827 Args:
37673828 operation: The dataset operation to wait for.
37683829 timeout: The maximum time to wait for the operation to complete.
3830+ max_wait_time: The maximum interval between polling requests in seconds.
37693831
37703832 Returns:
37713833 The name of the Dataset resource from the operation result.
@@ -3787,7 +3849,6 @@ async def _wait_for_operation(
37873849 start_time = time .time ()
37883850 sleep_duration = 5
37893851 wait_multiplier = 2
3790- max_wait_time = 60
37913852 previous_time = time .time ()
37923853
37933854 while not done :
@@ -3885,6 +3946,7 @@ async def _wait_for_project_operation(
38853946 self ,
38863947 operation : genai_types .ProjectOperation ,
38873948 timeout : int ,
3949+ max_wait_time : int = 60 ,
38883950 ) -> None :
38893951 """Waits for a dataset deletion operation to complete.
38903952
@@ -3893,6 +3955,7 @@ async def _wait_for_project_operation(
38933955 Args:
38943956 operation: The project operation to wait for.
38953957 timeout: The maximum time to wait for the operation to complete.
3958+ max_wait_time: The maximum interval between polling requests in seconds.
38963959 Raises:
38973960 TimeoutError: If the operation does not complete within the timeout.
38983961 ValueError: If the operation fails.
@@ -3902,7 +3965,6 @@ async def _wait_for_project_operation(
39023965 start_time = time .time ()
39033966 sleep_duration = 5
39043967 wait_multiplier = 2
3905- max_wait_time = 60
39063968 previous_time = time .time ()
39073969 while not done :
39083970 if (time .time () - start_time ) > timeout :
@@ -3947,7 +4009,13 @@ async def delete(
39474009 config = config ,
39484010 )
39494011 await self ._wait_for_project_operation (
3950- operation = delete_prompt_operation , timeout = config .timeout if config else 90
4012+ operation = delete_prompt_operation ,
4013+ timeout = config .timeout if config and config .timeout is not None else 90 ,
4014+ max_wait_time = (
4015+ config .max_wait_time
4016+ if config and config .max_wait_time is not None
4017+ else 60
4018+ ),
39514019 )
39524020 logger .info (f"Deleted prompt with id: { prompt_id } " )
39534021
@@ -3975,7 +4043,13 @@ async def delete_version(
39754043 )
39764044
39774045 await self ._wait_for_project_operation (
3978- operation = delete_version_operation , timeout = config .timeout if config else 90
4046+ operation = delete_version_operation ,
4047+ timeout = config .timeout if config and config .timeout is not None else 90 ,
4048+ max_wait_time = (
4049+ config .max_wait_time
4050+ if config and config .max_wait_time is not None
4051+ else 60
4052+ ),
39794053 )
39804054 logger .info (
39814055 f"Deleted prompt version { version_id } from prompt with id: { prompt_id } "
@@ -4111,10 +4185,16 @@ async def restore_version(
41114185 restore_prompt_operation = await self ._restore_version (
41124186 dataset_id = prompt_id ,
41134187 version_id = version_id ,
4188+ config = config ,
41144189 )
41154190 await self ._wait_for_project_operation (
41164191 operation = restore_prompt_operation ,
4117- timeout = 90 ,
4192+ timeout = config .timeout if config and config .timeout is not None else 90 ,
4193+ max_wait_time = (
4194+ config .max_wait_time
4195+ if config and config .max_wait_time is not None
4196+ else 60
4197+ ),
41184198 )
41194199 dataset_version_resource = await self ._get_dataset_version_resource (
41204200 dataset_id = prompt_id ,
0 commit comments