ansys-hps-data-transfer-client 0.2.1__tar.gz → 0.4.dev0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {ansys_hps_data_transfer_client-0.2.1 → ansys_hps_data_transfer_client-0.4.dev0}/PKG-INFO +9 -9
- {ansys_hps_data_transfer_client-0.2.1 → ansys_hps_data_transfer_client-0.4.dev0}/pyproject.toml +9 -9
- {ansys_hps_data_transfer_client-0.2.1 → ansys_hps_data_transfer_client-0.4.dev0}/src/ansys/hps/data_transfer/client/__init__.py +1 -0
- {ansys_hps_data_transfer_client-0.2.1 → ansys_hps_data_transfer_client-0.4.dev0}/src/ansys/hps/data_transfer/client/api/__init__.py +1 -0
- {ansys_hps_data_transfer_client-0.2.1 → ansys_hps_data_transfer_client-0.4.dev0}/src/ansys/hps/data_transfer/client/api/api.py +41 -27
- {ansys_hps_data_transfer_client-0.2.1 → ansys_hps_data_transfer_client-0.4.dev0}/src/ansys/hps/data_transfer/client/api/async_api.py +43 -21
- ansys_hps_data_transfer_client-0.4.dev0/src/ansys/hps/data_transfer/client/api/handler.py +123 -0
- {ansys_hps_data_transfer_client-0.2.1 → ansys_hps_data_transfer_client-0.4.dev0}/src/ansys/hps/data_transfer/client/binary.py +119 -46
- {ansys_hps_data_transfer_client-0.2.1 → ansys_hps_data_transfer_client-0.4.dev0}/src/ansys/hps/data_transfer/client/client.py +124 -20
- {ansys_hps_data_transfer_client-0.2.1 → ansys_hps_data_transfer_client-0.4.dev0}/src/ansys/hps/data_transfer/client/exceptions.py +26 -13
- {ansys_hps_data_transfer_client-0.2.1 → ansys_hps_data_transfer_client-0.4.dev0}/src/ansys/hps/data_transfer/client/models/__init__.py +2 -4
- {ansys_hps_data_transfer_client-0.2.1 → ansys_hps_data_transfer_client-0.4.dev0}/src/ansys/hps/data_transfer/client/models/common.py +3 -4
- {ansys_hps_data_transfer_client-0.2.1 → ansys_hps_data_transfer_client-0.4.dev0}/src/ansys/hps/data_transfer/client/models/core.py +3 -4
- {ansys_hps_data_transfer_client-0.2.1 → ansys_hps_data_transfer_client-0.4.dev0}/src/ansys/hps/data_transfer/client/models/metadata.py +6 -10
- {ansys_hps_data_transfer_client-0.2.1 → ansys_hps_data_transfer_client-0.4.dev0}/src/ansys/hps/data_transfer/client/models/msg.py +42 -67
- {ansys_hps_data_transfer_client-0.2.1 → ansys_hps_data_transfer_client-0.4.dev0}/src/ansys/hps/data_transfer/client/models/ops.py +7 -6
- {ansys_hps_data_transfer_client-0.2.1 → ansys_hps_data_transfer_client-0.4.dev0}/src/ansys/hps/data_transfer/client/models/permissions.py +1 -19
- {ansys_hps_data_transfer_client-0.2.1 → ansys_hps_data_transfer_client-0.4.dev0}/src/ansys/hps/data_transfer/client/models/rest.py +25 -5
- {ansys_hps_data_transfer_client-0.2.1 → ansys_hps_data_transfer_client-0.4.dev0}/src/ansys/hps/data_transfer/client/models/storage.py +1 -4
- {ansys_hps_data_transfer_client-0.2.1 → ansys_hps_data_transfer_client-0.4.dev0}/LICENSE +0 -0
- {ansys_hps_data_transfer_client-0.2.1 → ansys_hps_data_transfer_client-0.4.dev0}/README.rst +0 -0
- {ansys_hps_data_transfer_client-0.2.1 → ansys_hps_data_transfer_client-0.4.dev0}/src/ansys/hps/data_transfer/client/__version__.py +0 -0
- {ansys_hps_data_transfer_client-0.2.1 → ansys_hps_data_transfer_client-0.4.dev0}/src/ansys/hps/data_transfer/client/api/retry.py +0 -0
- {ansys_hps_data_transfer_client-0.2.1 → ansys_hps_data_transfer_client-0.4.dev0}/src/ansys/hps/data_transfer/client/authenticate.py +0 -0
- {ansys_hps_data_transfer_client-0.2.1 → ansys_hps_data_transfer_client-0.4.dev0}/src/ansys/hps/data_transfer/client/token.py +0 -0
- {ansys_hps_data_transfer_client-0.2.1 → ansys_hps_data_transfer_client-0.4.dev0}/src/ansys/hps/data_transfer/client/utils/__init__.py +0 -0
- {ansys_hps_data_transfer_client-0.2.1 → ansys_hps_data_transfer_client-0.4.dev0}/src/ansys/hps/data_transfer/client/utils/jitter.py +0 -0
- {ansys_hps_data_transfer_client-0.2.1 → ansys_hps_data_transfer_client-0.4.dev0}/src/ansys/hps/data_transfer/client/utils/otel_config.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: ansys-hps-data-transfer-client
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.dev0
|
|
4
4
|
Summary: Python client library for hps data transfer service
|
|
5
5
|
Author-email: "ANSYS, Inc." <pyansys.core@ansys.com>
|
|
6
6
|
Maintainer-email: "ANSYS, Inc." <pyansys.core@ansys.com>
|
|
@@ -24,10 +24,10 @@ Requires-Dist: asyncio-atexit>=1.0.0
|
|
|
24
24
|
Requires-Dist: build==1.2.2.post1 ; extra == "build"
|
|
25
25
|
Requires-Dist: twine==6.1.0 ; extra == "build"
|
|
26
26
|
Requires-Dist: wheel ; extra == "build"
|
|
27
|
-
Requires-Dist: datamodel-code-generator==0.
|
|
28
|
-
Requires-Dist: pre-commit==4.
|
|
27
|
+
Requires-Dist: datamodel-code-generator==0.33.0 ; extra == "build"
|
|
28
|
+
Requires-Dist: pre-commit==4.3.0 ; extra == "build"
|
|
29
29
|
Requires-Dist: importlib_metadata>=7.0 ; extra == "build"
|
|
30
|
-
Requires-Dist: ansys-sphinx-theme==1.
|
|
30
|
+
Requires-Dist: ansys-sphinx-theme==1.5.2 ; extra == "doc"
|
|
31
31
|
Requires-Dist: autodoc_pydantic==2.2.0 ; extra == "doc"
|
|
32
32
|
Requires-Dist: jupyter_sphinx==0.5.3 ; extra == "doc"
|
|
33
33
|
Requires-Dist: nbsphinx==0.9.7 ; extra == "doc"
|
|
@@ -43,15 +43,15 @@ Requires-Dist: sphinx-jinja==2.0.2 ; extra == "doc"
|
|
|
43
43
|
Requires-Dist: sphinxnotes-strike==1.2.1 ; extra == "doc"
|
|
44
44
|
Requires-Dist: sphinx-tabs==3.4.7 ; extra == "doc"
|
|
45
45
|
Requires-Dist: sphinx-gallery==0.19.0 ; extra == "doc"
|
|
46
|
-
Requires-Dist: pytest==8.
|
|
47
|
-
Requires-Dist: pytest-cov==6.
|
|
46
|
+
Requires-Dist: pytest==8.4.1 ; extra == "tests"
|
|
47
|
+
Requires-Dist: pytest-cov==6.2.1 ; extra == "tests"
|
|
48
48
|
Requires-Dist: pytest-timeout==2.4.0 ; extra == "tests"
|
|
49
49
|
Requires-Dist: pytest-mock-resources[redis]==2.12.2 ; extra == "tests"
|
|
50
50
|
Requires-Dist: pytest-rerunfailures==15.1 ; extra == "tests"
|
|
51
|
-
Requires-Dist: pytest-asyncio==
|
|
52
|
-
Requires-Dist: python-keycloak==5.
|
|
51
|
+
Requires-Dist: pytest-asyncio==1.1.0 ; extra == "tests"
|
|
52
|
+
Requires-Dist: python-keycloak==5.8.1 ; extra == "tests"
|
|
53
53
|
Requires-Dist: python-slugify>=8.0.4 ; extra == "tests"
|
|
54
|
-
Requires-Dist: tox==4.
|
|
54
|
+
Requires-Dist: tox==4.29.0 ; extra == "tests"
|
|
55
55
|
Project-URL: Documentation, https://data-transfer.hps.docs.pyansys.com
|
|
56
56
|
Project-URL: Homepage, https://github.com/ansys/pyhps-data-transfer/
|
|
57
57
|
Project-URL: Source, https://github.com/ansys/pyhps-data-transfer/
|
{ansys_hps_data_transfer_client-0.2.1 → ansys_hps_data_transfer_client-0.4.dev0}/pyproject.toml
RENAMED
|
@@ -5,7 +5,7 @@ build-backend = "flit_core.buildapi"
|
|
|
5
5
|
[project]
|
|
6
6
|
# Check https://flit.readthedocs.io/en/latest/pyproject_toml.html for all available sections
|
|
7
7
|
name = "ansys-hps-data-transfer-client"
|
|
8
|
-
version = "0.
|
|
8
|
+
version = "0.4.dev0"
|
|
9
9
|
description = "Python client library for hps data transfer service"
|
|
10
10
|
readme = "README.rst"
|
|
11
11
|
requires-python = ">=3.10,<4.0"
|
|
@@ -39,18 +39,18 @@ dependencies = [
|
|
|
39
39
|
|
|
40
40
|
[project.optional-dependencies]
|
|
41
41
|
tests = [
|
|
42
|
-
"pytest==8.
|
|
43
|
-
"pytest-cov==6.
|
|
42
|
+
"pytest==8.4.1",
|
|
43
|
+
"pytest-cov==6.2.1",
|
|
44
44
|
"pytest-timeout==2.4.0",
|
|
45
45
|
"pytest-mock-resources[redis]==2.12.2",
|
|
46
46
|
"pytest-rerunfailures==15.1",
|
|
47
|
-
"pytest-asyncio==
|
|
48
|
-
"python-keycloak==5.
|
|
47
|
+
"pytest-asyncio==1.1.0",
|
|
48
|
+
"python-keycloak==5.8.1",
|
|
49
49
|
"python-slugify>=8.0.4",
|
|
50
|
-
"tox==4.
|
|
50
|
+
"tox==4.29.0",
|
|
51
51
|
]
|
|
52
52
|
doc = [
|
|
53
|
-
"ansys-sphinx-theme==1.
|
|
53
|
+
"ansys-sphinx-theme==1.5.2",
|
|
54
54
|
"autodoc_pydantic==2.2.0",
|
|
55
55
|
"jupyter_sphinx==0.5.3",
|
|
56
56
|
"nbsphinx==0.9.7",
|
|
@@ -72,8 +72,8 @@ build = [
|
|
|
72
72
|
"build==1.2.2.post1",
|
|
73
73
|
"twine==6.1.0",
|
|
74
74
|
"wheel",
|
|
75
|
-
"datamodel-code-generator==0.
|
|
76
|
-
"pre-commit==4.
|
|
75
|
+
"datamodel-code-generator==0.33.0",
|
|
76
|
+
"pre-commit==4.3.0",
|
|
77
77
|
"importlib_metadata>=7.0",
|
|
78
78
|
]
|
|
79
79
|
|
|
@@ -27,12 +27,12 @@ data transfer operations, managing resources, and handling client interactions.
|
|
|
27
27
|
"""
|
|
28
28
|
|
|
29
29
|
import builtins
|
|
30
|
+
from collections.abc import Callable
|
|
30
31
|
import logging
|
|
31
|
-
import textwrap
|
|
32
32
|
import time
|
|
33
|
+
import traceback
|
|
33
34
|
|
|
34
35
|
import backoff
|
|
35
|
-
import humanfriendly as hf
|
|
36
36
|
|
|
37
37
|
from ..client import Client
|
|
38
38
|
from ..exceptions import TimeoutError
|
|
@@ -51,6 +51,7 @@ from ..models.msg import (
|
|
|
51
51
|
from ..models.ops import Operation, OperationState
|
|
52
52
|
from ..models.permissions import RoleAssignment, RoleQuery
|
|
53
53
|
from ..utils.jitter import get_expo_backoff
|
|
54
|
+
from .handler import WaitHandler
|
|
54
55
|
from .retry import retry
|
|
55
56
|
|
|
56
57
|
log = logging.getLogger(__name__)
|
|
@@ -69,6 +70,7 @@ class DataTransferApi:
|
|
|
69
70
|
"""Initializes the DataTransferApi class object."""
|
|
70
71
|
self.dump_mode = "json"
|
|
71
72
|
self.client = client
|
|
73
|
+
self.wait_handler_factory = WaitHandler
|
|
72
74
|
|
|
73
75
|
@retry()
|
|
74
76
|
def status(self, wait=False, sleep=5, jitter=True, timeout: float | None = 20.0):
|
|
@@ -94,7 +96,7 @@ class DataTransferApi:
|
|
|
94
96
|
return s
|
|
95
97
|
|
|
96
98
|
@retry()
|
|
97
|
-
def operations(self, ids: list[str]):
|
|
99
|
+
def operations(self, ids: list[str], expand: bool = False):
|
|
98
100
|
"""Get a list of operations.
|
|
99
101
|
|
|
100
102
|
Parameters
|
|
@@ -102,7 +104,7 @@ class DataTransferApi:
|
|
|
102
104
|
ids: List[str]
|
|
103
105
|
List of IDs.
|
|
104
106
|
"""
|
|
105
|
-
return self._operations(ids)
|
|
107
|
+
return self._operations(ids, expand=expand)
|
|
106
108
|
|
|
107
109
|
def storages(self):
|
|
108
110
|
"""Get types of storages available on the storage backend."""
|
|
@@ -185,9 +187,12 @@ class DataTransferApi:
|
|
|
185
187
|
r = OpIdResponse(**json)
|
|
186
188
|
return r
|
|
187
189
|
|
|
188
|
-
def _operations(self, ids: builtins.list[str]):
|
|
190
|
+
def _operations(self, ids: builtins.list[str], expand: bool = False):
|
|
189
191
|
url = "/operations"
|
|
190
|
-
|
|
192
|
+
params = {"ids": ids}
|
|
193
|
+
if expand:
|
|
194
|
+
params["expand"] = "true"
|
|
195
|
+
resp = self.client.session.get(url, params=params)
|
|
191
196
|
json = resp.json()
|
|
192
197
|
return OpsResponse(**json).operations
|
|
193
198
|
|
|
@@ -281,32 +286,45 @@ class DataTransferApi:
|
|
|
281
286
|
interval: float = 0.1,
|
|
282
287
|
cap: float = 2.0,
|
|
283
288
|
raise_on_error: bool = False,
|
|
289
|
+
handler: Callable[[builtins.list[Operation]], None] = None,
|
|
284
290
|
):
|
|
285
|
-
"""Wait for operations to complete.
|
|
291
|
+
"""Wait for operations to complete.
|
|
292
|
+
|
|
293
|
+
Parameters
|
|
294
|
+
----------
|
|
295
|
+
operation_ids: List[str | Operation | OpIdResponse]
|
|
296
|
+
List of operation ids.
|
|
297
|
+
timeout: float | None
|
|
298
|
+
Timeout in seconds. Default is None.
|
|
299
|
+
interval: float
|
|
300
|
+
Interval in seconds. Default is 0.1.
|
|
301
|
+
cap: float
|
|
302
|
+
The maximum backoff value used to calculate the next wait time. Default is 2.0.
|
|
303
|
+
raise_on_error: bool
|
|
304
|
+
Raise an exception if an error occurs. Default is False.
|
|
305
|
+
operation_handler: Callable[[builtins.list[Operation]], None]
|
|
306
|
+
A callable that will be called with the list of operations when they are fetched.
|
|
307
|
+
"""
|
|
308
|
+
if handler is None:
|
|
309
|
+
handler = self.wait_handler_factory()
|
|
310
|
+
|
|
286
311
|
if not isinstance(operation_ids, list):
|
|
287
312
|
operation_ids = [operation_ids]
|
|
288
313
|
operation_ids = [op.id if isinstance(op, Operation | OpIdResponse) else op for op in operation_ids]
|
|
289
314
|
start = time.time()
|
|
290
315
|
attempt = 0
|
|
291
|
-
op_str = textwrap.wrap(", ".join(operation_ids), width=60, placeholder="...")
|
|
292
|
-
# log.debug(f"Waiting for operations to complete: {op_str}")
|
|
293
316
|
while True:
|
|
294
317
|
attempt += 1
|
|
295
318
|
try:
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
f"succeeded_on={op.succeeded_on}",
|
|
306
|
-
]
|
|
307
|
-
if op.progress > 0:
|
|
308
|
-
fields.append(f"progress={op.progress:.3f}")
|
|
309
|
-
log.debug(f"- Operation '{op.description}' {' '.join(fields)}")
|
|
319
|
+
expand = getattr(handler.Meta, "expand_group", False) if hasattr(handler, "Meta") else False
|
|
320
|
+
ops = self._operations(operation_ids, expand=expand)
|
|
321
|
+
if handler is not None:
|
|
322
|
+
try:
|
|
323
|
+
handler(ops)
|
|
324
|
+
except Exception as e:
|
|
325
|
+
log.warning(f"Handler error: {e}")
|
|
326
|
+
log.debug(traceback.format_exc())
|
|
327
|
+
|
|
310
328
|
if all(op.state in [OperationState.Succeeded, OperationState.Failed] for op in ops):
|
|
311
329
|
break
|
|
312
330
|
except Exception as e:
|
|
@@ -319,10 +337,6 @@ class DataTransferApi:
|
|
|
319
337
|
|
|
320
338
|
# TODO: Adjust based on transfer speed and file size
|
|
321
339
|
duration = get_expo_backoff(interval, attempts=attempt, cap=cap, jitter=True)
|
|
322
|
-
if self.client.binary_config.debug:
|
|
323
|
-
log.debug(f"Next check in {hf.format_timespan(duration)} ...")
|
|
324
340
|
time.sleep(duration)
|
|
325
341
|
|
|
326
|
-
duration = hf.format_timespan(time.time() - start)
|
|
327
|
-
log.debug(f"Operations completed after {duration}: {op_str}")
|
|
328
342
|
return ops
|
|
@@ -28,9 +28,11 @@ data transfer operations asynchronously, managing resources, and handling client
|
|
|
28
28
|
|
|
29
29
|
import asyncio
|
|
30
30
|
import builtins
|
|
31
|
+
from collections.abc import Awaitable, Callable
|
|
31
32
|
import logging
|
|
32
33
|
import textwrap
|
|
33
34
|
import time
|
|
35
|
+
import traceback
|
|
34
36
|
|
|
35
37
|
import backoff
|
|
36
38
|
import humanfriendly as hf
|
|
@@ -52,6 +54,7 @@ from ..models.msg import (
|
|
|
52
54
|
from ..models.ops import Operation, OperationState
|
|
53
55
|
from ..models.permissions import RoleAssignment, RoleQuery
|
|
54
56
|
from ..utils.jitter import get_expo_backoff
|
|
57
|
+
from .handler import AsyncWaitHandler
|
|
55
58
|
from .retry import retry
|
|
56
59
|
|
|
57
60
|
log = logging.getLogger(__name__)
|
|
@@ -64,6 +67,7 @@ class AsyncDataTransferApi:
|
|
|
64
67
|
"""Initialize the async data transfer API with the client object."""
|
|
65
68
|
self.dump_mode = "json"
|
|
66
69
|
self.client = client
|
|
70
|
+
self.wait_handler_factory = AsyncWaitHandler
|
|
67
71
|
|
|
68
72
|
@retry()
|
|
69
73
|
async def status(self, wait=False, sleep=5, jitter=True, timeout: float | None = 20.0):
|
|
@@ -90,9 +94,9 @@ class AsyncDataTransferApi:
|
|
|
90
94
|
return s
|
|
91
95
|
|
|
92
96
|
@retry()
|
|
93
|
-
async def operations(self, ids: list[str]):
|
|
97
|
+
async def operations(self, ids: list[str], expand: bool = False):
|
|
94
98
|
"""Provides an async interface to get a list of operations by their IDs."""
|
|
95
|
-
return await self._operations(ids)
|
|
99
|
+
return await self._operations(ids, expand=expand)
|
|
96
100
|
|
|
97
101
|
async def storages(self):
|
|
98
102
|
"""Provides an async interface to get the list of storage configurations."""
|
|
@@ -139,9 +143,12 @@ class AsyncDataTransferApi:
|
|
|
139
143
|
json = resp.json()
|
|
140
144
|
return OpIdResponse(**json)
|
|
141
145
|
|
|
142
|
-
async def _operations(self, ids: builtins.list[str]):
|
|
146
|
+
async def _operations(self, ids: builtins.list[str], expand: bool = False):
|
|
143
147
|
url = "/operations"
|
|
144
|
-
|
|
148
|
+
params = {"ids": ids}
|
|
149
|
+
if expand:
|
|
150
|
+
params["expand"] = "true"
|
|
151
|
+
resp = await self.client.session.get(url, params=params)
|
|
145
152
|
json = resp.json()
|
|
146
153
|
return OpsResponse(**json).operations
|
|
147
154
|
|
|
@@ -204,8 +211,28 @@ class AsyncDataTransferApi:
|
|
|
204
211
|
interval: float = 0.1,
|
|
205
212
|
cap: float = 2.0,
|
|
206
213
|
raise_on_error: bool = False,
|
|
214
|
+
handler: Callable[[builtins.list[Operation]], Awaitable[None]] = None,
|
|
207
215
|
):
|
|
208
|
-
"""Provides an async interface to wait for a list of operations to complete.
|
|
216
|
+
"""Provides an async interface to wait for a list of operations to complete.
|
|
217
|
+
|
|
218
|
+
Parameters
|
|
219
|
+
----------
|
|
220
|
+
operation_ids: list[str | Operation]
|
|
221
|
+
The list of operation ids to wait for.
|
|
222
|
+
timeout: float | None
|
|
223
|
+
The maximum time to wait for the operations to complete.
|
|
224
|
+
interval: float
|
|
225
|
+
The interval between checks for the operations to complete.
|
|
226
|
+
cap: float
|
|
227
|
+
The maximum backoff value used to calculate the next wait time. Default is 2.0.
|
|
228
|
+
raise_on_error: bool
|
|
229
|
+
Raise an exception if an error occurs. Default is False.
|
|
230
|
+
operation_handler: Callable[[builtins.list[Operation]], None]
|
|
231
|
+
A callable that will be called with the list of operations when they are fetched.
|
|
232
|
+
"""
|
|
233
|
+
if handler is None:
|
|
234
|
+
handler = self.wait_handler_factory()
|
|
235
|
+
|
|
209
236
|
if not isinstance(operation_ids, list):
|
|
210
237
|
operation_ids = [operation_ids]
|
|
211
238
|
operation_ids = [op.id if isinstance(op, Operation | OpIdResponse) else op for op in operation_ids]
|
|
@@ -216,20 +243,15 @@ class AsyncDataTransferApi:
|
|
|
216
243
|
while True:
|
|
217
244
|
attempt += 1
|
|
218
245
|
try:
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
f"succeeded_on={op.succeeded_on}",
|
|
229
|
-
]
|
|
230
|
-
if op.progress > 0:
|
|
231
|
-
fields.append(f"progress={op.progress:.3f}")
|
|
232
|
-
log.debug(f"- Operation '{op.description}' {' '.join(fields)}")
|
|
246
|
+
expand = getattr(handler.Meta, "expand_group", False) if hasattr(handler, "Meta") else False
|
|
247
|
+
ops = await self._operations(operation_ids, expand=expand)
|
|
248
|
+
if handler is not None:
|
|
249
|
+
try:
|
|
250
|
+
await handler(ops)
|
|
251
|
+
except Exception as e:
|
|
252
|
+
log.warning(f"Handler error: {e}")
|
|
253
|
+
log.debug(traceback.format_exc())
|
|
254
|
+
|
|
233
255
|
if all(op.state in [OperationState.Succeeded, OperationState.Failed] for op in ops):
|
|
234
256
|
break
|
|
235
257
|
except Exception as e:
|
|
@@ -242,8 +264,8 @@ class AsyncDataTransferApi:
|
|
|
242
264
|
|
|
243
265
|
# TODO: Adjust based on transfer speed and file size
|
|
244
266
|
duration = get_expo_backoff(interval, attempts=attempt, cap=cap, jitter=True)
|
|
245
|
-
if self.client.binary_config.debug:
|
|
246
|
-
|
|
267
|
+
# if self.client.binary_config.debug:
|
|
268
|
+
# log.debug(f"Next check in {hf.format_timespan(duration)} ...")
|
|
247
269
|
await asyncio.sleep(duration)
|
|
248
270
|
|
|
249
271
|
duration = hf.format_timespan(time.time() - start)
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
# Copyright (C) 2025 ANSYS, Inc. and/or its affiliates.
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
#
|
|
4
|
+
#
|
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
# in the Software without restriction, including without limitation the rights
|
|
8
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
# furnished to do so, subject to the following conditions:
|
|
11
|
+
#
|
|
12
|
+
# The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
# copies or substantial portions of the Software.
|
|
14
|
+
#
|
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
# SOFTWARE.
|
|
22
|
+
|
|
23
|
+
"""Provides functionality for monitoring of operations."""
|
|
24
|
+
|
|
25
|
+
import datetime
|
|
26
|
+
import logging
|
|
27
|
+
import time
|
|
28
|
+
|
|
29
|
+
from dateutil import parser
|
|
30
|
+
import humanfriendly as hf
|
|
31
|
+
|
|
32
|
+
from ..models.ops import Operation, OperationState
|
|
33
|
+
|
|
34
|
+
log = logging.getLogger(__name__)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class WaitHandler:
|
|
38
|
+
"""Allows additional handling of operation status on wait."""
|
|
39
|
+
|
|
40
|
+
class Meta:
|
|
41
|
+
"""Meta class for WaitHandler."""
|
|
42
|
+
|
|
43
|
+
expand_group = True
|
|
44
|
+
|
|
45
|
+
final = [OperationState.Succeeded, OperationState.Failed]
|
|
46
|
+
|
|
47
|
+
def __init__(self):
|
|
48
|
+
"""Initializes the WaitHandler class object."""
|
|
49
|
+
self.start = time.time()
|
|
50
|
+
self.report_threshold = 2.0 # seconds
|
|
51
|
+
self.min_progress_interval = 3.0 # seconds
|
|
52
|
+
self.last_progress = self.start
|
|
53
|
+
|
|
54
|
+
def __call__(self, ops: list[Operation]):
|
|
55
|
+
"""Handle operations after they are fetched."""
|
|
56
|
+
self._log_ops(ops)
|
|
57
|
+
|
|
58
|
+
def _log_ops(self, ops: list[Operation]) -> str:
|
|
59
|
+
# so_far = time.time() - self.start
|
|
60
|
+
num_running = 0
|
|
61
|
+
for op in ops:
|
|
62
|
+
for ch in op.children_detail or []:
|
|
63
|
+
if ch.state not in self.final:
|
|
64
|
+
num_running += 1
|
|
65
|
+
self._log_op(logging.DEBUG, ch)
|
|
66
|
+
|
|
67
|
+
if op.state not in self.final:
|
|
68
|
+
num_running += 1
|
|
69
|
+
self._log_op(logging.INFO, op)
|
|
70
|
+
|
|
71
|
+
def _log_op(self, lvl: int, op: Operation):
|
|
72
|
+
"""Format the operation description."""
|
|
73
|
+
op_type = "operation" if len(op.children) == 0 else "operation group"
|
|
74
|
+
|
|
75
|
+
msg = f"Data transfer {op_type} '{op.description}'({op.id})"
|
|
76
|
+
|
|
77
|
+
op_done = op.state in self.final
|
|
78
|
+
try:
|
|
79
|
+
start = parser.parse(op.started_at)
|
|
80
|
+
if op_done:
|
|
81
|
+
end = parser.parse(op.ended_at)
|
|
82
|
+
else:
|
|
83
|
+
end = datetime.datetime.now(start.tzinfo)
|
|
84
|
+
duration = (end - start).seconds
|
|
85
|
+
duration_str = hf.format_timespan(end - start)
|
|
86
|
+
except Exception as ex:
|
|
87
|
+
log.debug(f"Failed to parse operation duration: {ex}")
|
|
88
|
+
duration = 0
|
|
89
|
+
duration_str = "unknown"
|
|
90
|
+
|
|
91
|
+
state = op.state.value
|
|
92
|
+
if op_done:
|
|
93
|
+
msg += f" has {state} after {duration_str}"
|
|
94
|
+
msg += self._info_str(op)
|
|
95
|
+
# if op.messages:
|
|
96
|
+
# msg += f', messages="{"; ".join(op.messages)}"'
|
|
97
|
+
log.log(lvl, msg)
|
|
98
|
+
elif duration > self.report_threshold and time.time() - self.last_progress > self.min_progress_interval:
|
|
99
|
+
self.last_progress = time.time()
|
|
100
|
+
msg += f" is {state}, {duration_str} so far"
|
|
101
|
+
if op.progress_current > 0:
|
|
102
|
+
msg += f", progress {op.progress * 100.0:.1f}%"
|
|
103
|
+
msg += self._info_str(op)
|
|
104
|
+
log.log(lvl, msg)
|
|
105
|
+
|
|
106
|
+
def _info_str(self, op: Operation) -> str:
|
|
107
|
+
"""Format the operation info."""
|
|
108
|
+
if not op.info:
|
|
109
|
+
return ""
|
|
110
|
+
info = ", ".join([f"{k}={v}" for k, v in op.info.items()])
|
|
111
|
+
return f", {info}"
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
class AsyncWaitHandler(WaitHandler):
|
|
115
|
+
"""Allows additional, asynchronous handling of operation status on wait."""
|
|
116
|
+
|
|
117
|
+
def __init__(self):
|
|
118
|
+
"""Initializes the AsyncOperationHandler class object."""
|
|
119
|
+
super().__init__()
|
|
120
|
+
|
|
121
|
+
async def __call__(self, ops: list[Operation]):
|
|
122
|
+
"""Handle operations after they are fetched."""
|
|
123
|
+
self._log_ops(ops)
|