|
6 | 6 |
|
7 | 7 | import base64 |
8 | 8 | import json |
| 9 | +import time |
9 | 10 | from datetime import date |
10 | | -from time import sleep |
11 | 11 | from typing import TYPE_CHECKING, BinaryIO |
12 | 12 | from urllib.parse import urljoin |
13 | 13 |
|
14 | 14 | import requests |
15 | | -from func_timeout import func_set_timeout |
16 | | -from func_timeout.exceptions import FunctionTimedOut |
17 | 15 | from requests import Response |
18 | 16 | from vws_auth_tools import authorization_header, rfc_1123_date |
19 | 17 |
|
@@ -332,39 +330,6 @@ def get_target_record(self, target_id: str) -> TargetStatusAndRecord: |
332 | 330 | target_record=target_record, |
333 | 331 | ) |
334 | 332 |
|
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 | | - |
368 | 333 | def wait_for_target_processed( |
369 | 334 | self, |
370 | 335 | target_id: str, |
@@ -400,19 +365,18 @@ def wait_for_target_processed( |
400 | 365 | ~vws.exceptions.vws_exceptions.RequestTimeTooSkewed: There is an |
401 | 366 | error with the time sent to Vuforia. |
402 | 367 | """ |
| 368 | + start_time = time.monotonic() |
| 369 | + while True: |
| 370 | + report = self.get_target_summary_report(target_id=target_id) |
| 371 | + if report.status != TargetStatuses.PROCESSING: |
| 372 | + return |
| 373 | + |
| 374 | + if timeout_seconds is not None: |
| 375 | + elapsed_time = time.monotonic() - start_time |
| 376 | + if elapsed_time > timeout_seconds: # pragma: no cover |
| 377 | + raise TargetProcessingTimeout |
403 | 378 |
|
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 |
| 379 | + time.sleep(seconds_between_requests) |
416 | 380 |
|
417 | 381 | def list_targets(self) -> list[str]: |
418 | 382 | """ |
|
0 commit comments