66
77import base64
88import json
9+ import time
910from datetime import date
10- from time import sleep
1111from typing import TYPE_CHECKING , BinaryIO
1212from urllib .parse import urljoin
1313
1414import requests
15- from func_timeout import func_set_timeout
16- from func_timeout .exceptions import FunctionTimedOut
1715from requests import Response
1816from vws_auth_tools import authorization_header , rfc_1123_date
1917
@@ -332,44 +330,11 @@ def get_target_record(self, target_id: str) -> TargetStatusAndRecord:
332330 target_record = target_record ,
333331 )
334332
335- def _wait_for_target_processed (
336- self ,
337- target_id : str ,
338- seconds_between_requests : float ,
339- ) -> None :
340- """
341- Wait indefinitely for a target to get past the processing stage.
342-
343- Args:
344- target_id: The ID of the target to wait for.
345- seconds_between_requests: The number of seconds to wait between
346- requests made while polling the target status.
347-
348- Raises:
349- ~vws.exceptions.vws_exceptions.AuthenticationFailure: The secret
350- key is not correct.
351- ~vws.exceptions.vws_exceptions.Fail: There was an error with the
352- request. For example, the given access key does not match a
353- known database.
354- TimeoutError: The target remained in the processing stage for more
355- than five minutes.
356- ~vws.exceptions.vws_exceptions.UnknownTarget: The given target ID
357- does not match a target in the database.
358- ~vws.exceptions.vws_exceptions.RequestTimeTooSkewed: There is an
359- error with the time sent to Vuforia.
360- """
361- while True :
362- report = self .get_target_summary_report (target_id = target_id )
363- if report .status != TargetStatuses .PROCESSING :
364- return
365-
366- sleep (seconds_between_requests )
367-
368333 def wait_for_target_processed (
369334 self ,
370335 target_id : str ,
371336 seconds_between_requests : float = 0.2 ,
372- timeout_seconds : float | None = 60 * 5 ,
337+ timeout_seconds : float = 60 * 5 ,
373338 ) -> None :
374339 """
375340 Wait up to five minutes (arbitrary) for a target to get past the
@@ -383,8 +348,7 @@ def wait_for_target_processed(
383348 decrease the number of calls made to the API, to decrease the
384349 likelihood of hitting the request quota.
385350 timeout_seconds: The maximum number of seconds to wait for the
386- target to be processed. If ``None`` is given, no maximum is
387- applied.
351+ target to be processed.
388352
389353 Raises:
390354 ~vws.exceptions.vws_exceptions.AuthenticationFailure: The secret
@@ -400,19 +364,17 @@ def wait_for_target_processed(
400364 ~vws.exceptions.vws_exceptions.RequestTimeTooSkewed: There is an
401365 error with the time sent to Vuforia.
402366 """
367+ start_time = time .monotonic ()
368+ while True :
369+ report = self .get_target_summary_report (target_id = target_id )
370+ if report .status != TargetStatuses .PROCESSING :
371+ return
372+
373+ elapsed_time = time .monotonic () - start_time
374+ if elapsed_time > timeout_seconds : # pragma: no cover
375+ raise TargetProcessingTimeout
403376
404- # func_timeout does not have type hints.
405- @func_set_timeout (timeout = timeout_seconds ) # type: ignore[misc]
406- def decorated () -> None :
407- self ._wait_for_target_processed (
408- target_id = target_id ,
409- seconds_between_requests = seconds_between_requests ,
410- )
411-
412- try :
413- decorated ()
414- except FunctionTimedOut as exc :
415- raise TargetProcessingTimeout from exc
377+ time .sleep (seconds_between_requests )
416378
417379 def list_targets (self ) -> list [str ]:
418380 """
0 commit comments