Skip to content

Commit 1450d05

Browse files
Merge pull request #890 from adamtheturtle/better-timeout-error
Better timeout error
2 parents 9bf4add + 9440f1a commit 1450d05

File tree

1 file changed

+37
-8
lines changed

1 file changed

+37
-8
lines changed

src/vws/vws.py

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -276,14 +276,18 @@ def get_target_record(self, target_id: str) -> Dict[str, Union[str, int]]:
276276

277277
return dict(response.json()['target_record'])
278278

279-
@timeout_decorator.timeout(seconds=60 * 5)
280-
def wait_for_target_processed(self, target_id: str) -> None:
279+
def _wait_for_target_processed(
280+
self,
281+
target_id: str,
282+
seconds_between_requests: float,
283+
) -> None:
281284
"""
282-
Wait up to five minutes (arbitrary) for a target to get past the
283-
processing stage.
285+
Wait indefinitely for a target to get past the processing stage.
284286
285287
Args:
286288
target_id: The ID of the target to wait for.
289+
seconds_between_requests: The number of seconds to wait between
290+
requests made while polling the target status.
287291
288292
Raises:
289293
~vws.exceptions.AuthenticationFailure: The secret key is not
@@ -300,10 +304,35 @@ def wait_for_target_processed(self, target_id: str) -> None:
300304
if report['status'] != 'processing':
301305
return
302306

303-
# We wait 0.2 seconds rather than less than that to decrease the
304-
# number of calls made to the API, to decrease the likelihood of
305-
# hitting the request quota.
306-
sleep(0.2)
307+
sleep(seconds_between_requests)
308+
309+
@timeout_decorator.timeout(seconds=60 * 5)
310+
def wait_for_target_processed(self, target_id: str) -> None:
311+
"""
312+
Wait up to five minutes (arbitrary) for a target to get past the
313+
processing stage.
314+
315+
Args:
316+
target_id: The ID of the target to wait for.
317+
318+
Raises:
319+
~vws.exceptions.AuthenticationFailure: The secret key is not
320+
correct.
321+
~vws.exceptions.Fail: There was an error with the request. For
322+
example, the given access key does not match a known database.
323+
TimeoutError: The target remained in the processing stage for more
324+
than five minutes.
325+
~vws.exceptions.UnknownTarget: The given target ID does not match a
326+
target in the database.
327+
"""
328+
# We wait 0.2 seconds rather than less than that to decrease the
329+
# number of calls made to the API, to decrease the likelihood of
330+
# hitting the request quota.
331+
seconds_between_requests = 0.2
332+
self._wait_for_target_processed(
333+
target_id=target_id,
334+
seconds_between_requests=seconds_between_requests,
335+
)
307336

308337
def list_targets(self) -> List[str]:
309338
"""

0 commit comments

Comments
 (0)