@@ -164,17 +164,12 @@ def update_cc_pair_status(
164
164
db_session : Session = Depends (get_session ),
165
165
tenant_id : str | None = Depends (get_current_tenant_id ),
166
166
) -> JSONResponse :
167
- """This method may wait up to 30 seconds if pausing the connector due to the need to
168
- terminate tasks in progress. Tasks are not guaranteed to terminate within the
169
- timeout .
167
+ """This method returns nearly immediately. It simply sets some signals and
168
+ optimistically assumes any running background processes will clean themselves up.
169
+ This is done to improve the perceived end user experience .
170
170
171
171
Returns HTTPStatus.OK if everything finished.
172
- Returns HTTPStatus.ACCEPTED if the connector is being paused, but background tasks
173
- did not finish within the timeout.
174
172
"""
175
- WAIT_TIMEOUT = 15.0
176
- still_terminating = False
177
-
178
173
cc_pair = get_connector_credential_pair_from_id (
179
174
cc_pair_id = cc_pair_id ,
180
175
db_session = db_session ,
@@ -188,73 +183,37 @@ def update_cc_pair_status(
188
183
detail = "Connection not found for current user's permissions" ,
189
184
)
190
185
186
+ redis_connector = RedisConnector (tenant_id , cc_pair_id )
191
187
if status_update_request .status == ConnectorCredentialPairStatus .PAUSED :
188
+ redis_connector .stop .set_fence (True )
189
+
192
190
search_settings_list : list [SearchSettings ] = get_active_search_settings (
193
191
db_session
194
192
)
195
193
196
- redis_connector = RedisConnector (tenant_id , cc_pair_id )
197
-
198
- try :
199
- redis_connector .stop .set_fence (True )
200
- while True :
201
- logger .debug (
202
- f"Wait for indexing soft termination starting: cc_pair={ cc_pair_id } "
203
- )
204
- wait_succeeded = redis_connector .wait_for_indexing_termination (
205
- search_settings_list , WAIT_TIMEOUT
206
- )
207
- if wait_succeeded :
208
- logger .debug (
209
- f"Wait for indexing soft termination succeeded: cc_pair={ cc_pair_id } "
210
- )
211
- break
212
-
213
- logger .debug (
214
- "Wait for indexing soft termination timed out. "
215
- f"Moving to hard termination: cc_pair={ cc_pair_id } timeout={ WAIT_TIMEOUT :.2f} "
216
- )
217
-
218
- for search_settings in search_settings_list :
219
- redis_connector_index = redis_connector .new_index (
220
- search_settings .id
221
- )
222
- if not redis_connector_index .fenced :
223
- continue
224
-
225
- index_payload = redis_connector_index .payload
226
- if not index_payload :
227
- continue
228
-
229
- if not index_payload .celery_task_id :
230
- continue
231
-
232
- # Revoke the task to prevent it from running
233
- primary_app .control .revoke (index_payload .celery_task_id )
234
-
235
- # If it is running, then signaling for termination will get the
236
- # watchdog thread to kill the spawned task
237
- redis_connector_index .set_terminate (index_payload .celery_task_id )
238
-
239
- logger .debug (
240
- f"Wait for indexing hard termination starting: cc_pair={ cc_pair_id } "
241
- )
242
- wait_succeeded = redis_connector .wait_for_indexing_termination (
243
- search_settings_list , WAIT_TIMEOUT
244
- )
245
- if wait_succeeded :
246
- logger .debug (
247
- f"Wait for indexing hard termination succeeded: cc_pair={ cc_pair_id } "
248
- )
249
- break
250
-
251
- logger .debug (
252
- f"Wait for indexing hard termination timed out: cc_pair={ cc_pair_id } "
253
- )
254
- still_terminating = True
255
- break
256
- finally :
257
- redis_connector .stop .set_fence (False )
194
+ while True :
195
+ for search_settings in search_settings_list :
196
+ redis_connector_index = redis_connector .new_index (search_settings .id )
197
+ if not redis_connector_index .fenced :
198
+ continue
199
+
200
+ index_payload = redis_connector_index .payload
201
+ if not index_payload :
202
+ continue
203
+
204
+ if not index_payload .celery_task_id :
205
+ continue
206
+
207
+ # Revoke the task to prevent it from running
208
+ primary_app .control .revoke (index_payload .celery_task_id )
209
+
210
+ # If it is running, then signaling for termination will get the
211
+ # watchdog thread to kill the spawned task
212
+ redis_connector_index .set_terminate (index_payload .celery_task_id )
213
+
214
+ break
215
+ else :
216
+ redis_connector .stop .set_fence (False )
258
217
259
218
update_connector_credential_pair_from_id (
260
219
db_session = db_session ,
@@ -264,14 +223,6 @@ def update_cc_pair_status(
264
223
265
224
db_session .commit ()
266
225
267
- if still_terminating :
268
- return JSONResponse (
269
- status_code = HTTPStatus .ACCEPTED ,
270
- content = {
271
- "message" : "Request accepted, background task termination still in progress"
272
- },
273
- )
274
-
275
226
return JSONResponse (
276
227
status_code = HTTPStatus .OK , content = {"message" : str (HTTPStatus .OK )}
277
228
)
0 commit comments