Skip to content

Commit 88b0ead

Browse files
committed
Attempt to move decorated function to new module for Windows
1 parent 8fffd37 commit 88b0ead

File tree

2 files changed

+52
-40
lines changed

2 files changed

+52
-40
lines changed

src/vws/_wait_for_target_processed.py

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,71 @@
11
"""
2-
This is tooling for waiting for a target to be processed.
2+
Tooling for waiting for a target to be processed.
33
44
It lives here rather than in ``vws.py`` to support Windows.
55
"""
66

7+
from time import sleep
78
from typing import Optional
89

910
from wrapt_timeout_decorator import timeout
1011

11-
from vws import VWS
12+
import vws
1213
from vws.exceptions import TargetProcessingTimeout
14+
from vws.reports import TargetStatuses
15+
16+
17+
def _wait_for_target_processed(
18+
vws_client: 'vws.VWS',
19+
target_id: str,
20+
seconds_between_requests: float,
21+
) -> None:
22+
"""
23+
Wait indefinitely for a target to get past the processing stage.
24+
25+
Args:
26+
vws_client: The VWS client to make requests with.
27+
target_id: The ID of the target to wait for.
28+
seconds_between_requests: The number of seconds to wait between
29+
requests made while polling the target status.
30+
31+
Raises:
32+
~vws.exceptions.AuthenticationFailure: The secret key is not
33+
correct.
34+
~vws.exceptions.Fail: There was an error with the request. For
35+
example, the given access key does not match a known database.
36+
TimeoutError: The target remained in the processing stage for more
37+
than five minutes.
38+
~vws.exceptions.UnknownTarget: The given target ID does not match a
39+
target in the database.
40+
~vws.exceptions.RequestTimeTooSkewed: There is an error with the
41+
time sent to Vuforia.
42+
"""
43+
while True:
44+
report = vws_client.get_target_summary_report(target_id=target_id)
45+
if report.status != TargetStatuses.PROCESSING:
46+
return
47+
48+
sleep(seconds_between_requests)
1349

1450

1551
def foobar(
16-
vws_client: VWS,
52+
vws_client: 'vws.VWS',
1753
timeout_seconds: Optional[float],
1854
seconds_between_requests: float,
1955
target_id: str,
20-
):
56+
) -> None:
57+
"""
58+
Add Windows support.
59+
"""
2160

2261
@timeout(
2362
dec_timeout=timeout_seconds,
2463
timeout_exception=TargetProcessingTimeout,
2564
use_signals=False,
2665
)
2766
def decorated() -> None:
28-
vws_client._wait_for_target_processed(
67+
_wait_for_target_processed(
68+
vws_client=vws_client,
2969
target_id=target_id,
3070
seconds_between_requests=seconds_between_requests,
3171
)

src/vws/vws.py

Lines changed: 7 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import io
77
import json
88
from datetime import date
9-
from time import sleep
109
from typing import Dict, List, Optional, Union
1110
from urllib.parse import urljoin
1211

@@ -15,6 +14,7 @@
1514
from vws_auth_tools import authorization_header, rfc_1123_date
1615

1716
from vws._result_codes import raise_for_result_code
17+
from vws._wait_for_target_processed import foobar
1818
from vws.reports import (
1919
DatabaseSummaryReport,
2020
TargetRecord,
@@ -253,38 +253,6 @@ def get_target_record(self, target_id: str) -> TargetRecord:
253253
)
254254
return target_record
255255

256-
def _wait_for_target_processed(
257-
self,
258-
target_id: str,
259-
seconds_between_requests: float,
260-
) -> None:
261-
"""
262-
Wait indefinitely for a target to get past the processing stage.
263-
264-
Args:
265-
target_id: The ID of the target to wait for.
266-
seconds_between_requests: The number of seconds to wait between
267-
requests made while polling the target status.
268-
269-
Raises:
270-
~vws.exceptions.AuthenticationFailure: The secret key is not
271-
correct.
272-
~vws.exceptions.Fail: There was an error with the request. For
273-
example, the given access key does not match a known database.
274-
TimeoutError: The target remained in the processing stage for more
275-
than five minutes.
276-
~vws.exceptions.UnknownTarget: The given target ID does not match a
277-
target in the database.
278-
~vws.exceptions.RequestTimeTooSkewed: There is an error with the
279-
time sent to Vuforia.
280-
"""
281-
while True:
282-
report = self.get_target_summary_report(target_id=target_id)
283-
if report.status != TargetStatuses.PROCESSING:
284-
return
285-
286-
sleep(seconds_between_requests)
287-
288256
def wait_for_target_processed(
289257
self,
290258
target_id: str,
@@ -318,8 +286,12 @@ def wait_for_target_processed(
318286
~vws.exceptions.RequestTimeTooSkewed: There is an error with the
319287
time sent to Vuforia.
320288
"""
321-
from _wait_for_target_processed import foobar
322-
foobar(vws_client=self)
289+
foobar(
290+
vws_client=self,
291+
target_id=target_id,
292+
timeout_seconds=timeout_seconds,
293+
seconds_between_requests=seconds_between_requests,
294+
)
323295

324296
def list_targets(self) -> List[str]:
325297
"""

0 commit comments

Comments
 (0)