@@ -110,42 +110,28 @@ async def create_from_backup(
110
110
return await self .__poll_describe_index_until_ready (name , timeout )
111
111
112
112
async def __poll_describe_index_until_ready (self , name : str , timeout : Optional [int ] = None ):
113
- description = None
114
-
115
- async def is_ready () -> bool :
116
- nonlocal description
117
- description = await self .describe (name = name )
118
- return description .status .ready
119
-
120
113
total_wait_time = 0
121
- if timeout is None :
122
- # Wait indefinitely
123
- while not await is_ready ():
124
- logger .debug (
125
- f"Waiting for index { name } to be ready. Total wait time { total_wait_time } seconds."
114
+ while True :
115
+ description = await self .describe (name = name )
116
+ if description .status .state == "InitializationFailed" :
117
+ raise Exception (f"Index { name } failed to initialize." )
118
+ if description .status .ready :
119
+ return description
120
+
121
+ if timeout is not None and total_wait_time >= timeout :
122
+ logger .error (
123
+ f"Index { name } is not ready after { total_wait_time } seconds. Timeout reached."
126
124
)
127
- total_wait_time += 5
128
- await asyncio .sleep (5 )
125
+ link = docslinks ["API_DESCRIBE_INDEX" ](API_VERSION )
126
+ timeout_msg = f"Index { name } is not ready after { total_wait_time } seconds. Please call describe_index() to confirm index status. See docs at { link } "
127
+ raise TimeoutError (timeout_msg )
129
128
130
- else :
131
- # Wait for a maximum of timeout seconds
132
- while not await is_ready ():
133
- if timeout < 0 :
134
- logger .error (f"Index { name } is not ready. Timeout reached." )
135
- link = docslinks ["API_DESCRIBE_INDEX" ](API_VERSION )
136
- timeout_msg = (
137
- f"Please call describe_index() to confirm index status. See docs at { link } "
138
- )
139
- raise TimeoutError (timeout_msg )
140
-
141
- logger .debug (
142
- f"Waiting for index { name } to be ready. Total wait time: { total_wait_time } "
143
- )
144
- total_wait_time += 5
145
- await asyncio .sleep (5 )
146
- timeout -= 5
129
+ logger .debug (
130
+ f"Waiting for index { name } to be ready. Total wait time { total_wait_time } seconds."
131
+ )
147
132
148
- return description
133
+ total_wait_time += 5
134
+ await asyncio .sleep (5 )
149
135
150
136
@require_kwargs
151
137
async def delete (self , * , name : str , timeout : Optional [int ] = None ):
0 commit comments