Skip to content

Commit 5ee8751

Browse files
committed
Simplify changes
1 parent 6a7aaff commit 5ee8751

File tree

2 files changed

+44
-82
lines changed

2 files changed

+44
-82
lines changed

src/vws/_wait_for_target_processed.py

Lines changed: 0 additions & 73 deletions
This file was deleted.

src/vws/vws.py

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66
import io
77
import json
88
from datetime import date
9+
from time import sleep
910
from typing import Dict, List, Optional, Union
1011
from urllib.parse import urljoin
1112

1213
import requests
1314
from requests import Response
15+
from timeout_decorator import timeout
1416
from vws_auth_tools import authorization_header, rfc_1123_date
1517

16-
from func_timeout.exceptions import FunctionTimedOut
17-
from vws.exceptions import TargetProcessingTimeout
1818
from vws._result_codes import raise_for_result_code
19-
from vws._wait_for_target_processed import foobar
19+
from vws.exceptions import TargetProcessingTimeout
2020
from vws.reports import (
2121
DatabaseSummaryReport,
2222
TargetRecord,
@@ -255,6 +255,38 @@ def get_target_record(self, target_id: str) -> TargetRecord:
255255
)
256256
return target_record
257257

258+
def _wait_for_target_processed(
259+
self,
260+
target_id: str,
261+
seconds_between_requests: float,
262+
) -> None:
263+
"""
264+
Wait indefinitely for a target to get past the processing stage.
265+
266+
Args:
267+
target_id: The ID of the target to wait for.
268+
seconds_between_requests: The number of seconds to wait between
269+
requests made while polling the target status.
270+
271+
Raises:
272+
~vws.exceptions.AuthenticationFailure: The secret key is not
273+
correct.
274+
~vws.exceptions.Fail: There was an error with the request. For
275+
example, the given access key does not match a known database.
276+
TimeoutError: The target remained in the processing stage for more
277+
than five minutes.
278+
~vws.exceptions.UnknownTarget: The given target ID does not match a
279+
target in the database.
280+
~vws.exceptions.RequestTimeTooSkewed: There is an error with the
281+
time sent to Vuforia.
282+
"""
283+
while True:
284+
report = self.get_target_summary_report(target_id=target_id)
285+
if report.status != TargetStatuses.PROCESSING:
286+
return
287+
288+
sleep(seconds_between_requests)
289+
258290
def wait_for_target_processed(
259291
self,
260292
target_id: str,
@@ -288,15 +320,18 @@ def wait_for_target_processed(
288320
~vws.exceptions.RequestTimeTooSkewed: There is an error with the
289321
time sent to Vuforia.
290322
"""
291-
try:
292-
foobar(
293-
vws_client=self,
323+
324+
@timeout(
325+
seconds=timeout_seconds,
326+
timeout_exception=TargetProcessingTimeout,
327+
)
328+
def decorated() -> None:
329+
self._wait_for_target_processed(
294330
target_id=target_id,
295-
timeout_seconds=timeout_seconds,
296331
seconds_between_requests=seconds_between_requests,
297332
)
298-
except FunctionTimedOut:
299-
raise TargetProcessingTimeout
333+
334+
decorated()
300335

301336
def list_targets(self) -> List[str]:
302337
"""

0 commit comments

Comments
 (0)