evo-compute 0.0.1rc0__py3-none-any.whl
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.
- evo/compute/__init__.py +19 -0
- evo/compute/client.py +324 -0
- evo/compute/data.py +41 -0
- evo/compute/endpoints/__init__.py +33 -0
- evo/compute/endpoints/api/__init__.py +13 -0
- evo/compute/endpoints/api/job_api.py +264 -0
- evo/compute/endpoints/api/task_api.py +117 -0
- evo/compute/endpoints/models.py +80 -0
- evo/compute/exceptions.py +43 -0
- evo_compute-0.0.1rc0.dist-info/METADATA +78 -0
- evo_compute-0.0.1rc0.dist-info/RECORD +13 -0
- evo_compute-0.0.1rc0.dist-info/WHEEL +4 -0
- evo_compute-0.0.1rc0.dist-info/licenses/LICENSE.md +190 -0
evo/compute/__init__.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Copyright © 2025 Bentley Systems, Incorporated
|
|
2
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
# you may not use this file except in compliance with the License.
|
|
4
|
+
# You may obtain a copy of the License at
|
|
5
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
7
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
8
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
9
|
+
# See the License for the specific language governing permissions and
|
|
10
|
+
# limitations under the License.
|
|
11
|
+
|
|
12
|
+
from .client import JobClient
|
|
13
|
+
from .data import JobProgress, JobStatusEnum
|
|
14
|
+
|
|
15
|
+
__all__ = [
|
|
16
|
+
"JobClient",
|
|
17
|
+
"JobProgress",
|
|
18
|
+
"JobStatusEnum",
|
|
19
|
+
]
|
evo/compute/client.py
ADDED
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
# Copyright © 2025 Bentley Systems, Incorporated
|
|
2
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
# you may not use this file except in compliance with the License.
|
|
4
|
+
# You may obtain a copy of the License at
|
|
5
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
7
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
8
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
9
|
+
# See the License for the specific language governing permissions and
|
|
10
|
+
# limitations under the License.
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
import asyncio
|
|
15
|
+
import copy
|
|
16
|
+
import json
|
|
17
|
+
import re
|
|
18
|
+
from collections.abc import Iterator, Mapping
|
|
19
|
+
from contextlib import contextmanager
|
|
20
|
+
from typing import Any, Generic, TypeVar
|
|
21
|
+
from uuid import UUID
|
|
22
|
+
|
|
23
|
+
from evo.common import APIConnector, HTTPResponse
|
|
24
|
+
from evo.common.exceptions import UnknownResponseError
|
|
25
|
+
from evo.common.interfaces import IFeedback
|
|
26
|
+
from evo.common.utils import NoFeedback, Retry
|
|
27
|
+
from pydantic import TypeAdapter, ValidationError
|
|
28
|
+
|
|
29
|
+
from evo import logging
|
|
30
|
+
|
|
31
|
+
from .data import JobProgress, JobStatusEnum
|
|
32
|
+
from .endpoints import JobApi, TaskApi
|
|
33
|
+
from .endpoints.models import CompletedJobResponse
|
|
34
|
+
from .exceptions import JobError, JobPendingError
|
|
35
|
+
|
|
36
|
+
logger = logging.getLogger("compute.client")
|
|
37
|
+
|
|
38
|
+
__all__ = [
|
|
39
|
+
"JobClient",
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
T_Result = TypeVar("T_Result")
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
@contextmanager
|
|
46
|
+
def _validating_pydantic_model(ctx: HTTPResponse) -> Iterator[None]:
|
|
47
|
+
"""Context manager to handle Pydantic model validation errors.
|
|
48
|
+
|
|
49
|
+
:param ctx: The HTTP response context.
|
|
50
|
+
|
|
51
|
+
:raises UnknownResponseError: If the managed context raises a pydantic ValidationError.
|
|
52
|
+
"""
|
|
53
|
+
try:
|
|
54
|
+
yield
|
|
55
|
+
except ValidationError as e:
|
|
56
|
+
logger.error(f"Failed to validate response: {e}", exc_info=e)
|
|
57
|
+
|
|
58
|
+
content = ctx.data
|
|
59
|
+
try:
|
|
60
|
+
content = content.decode("utf-8") # Raises UnicodeDecodeError.
|
|
61
|
+
content = json.loads(content) # Raises json.JSONDecodeError.
|
|
62
|
+
except (UnicodeDecodeError, json.JSONDecodeError):
|
|
63
|
+
pass # content will fall back to the most specific valid value.
|
|
64
|
+
|
|
65
|
+
raise UnknownResponseError(
|
|
66
|
+
status=ctx.status,
|
|
67
|
+
reason=ctx.reason,
|
|
68
|
+
content=content,
|
|
69
|
+
headers=ctx.headers,
|
|
70
|
+
) from e
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
RE_STATUS_URL = re.compile(r"compute/orgs/(?P<org_id>[^/]+)/(?P<topic>[^/]+)/(?P<task>[^/]+)/(?P<job_id>[^/]+)/status")
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
class JobClient(Generic[T_Result]):
|
|
77
|
+
"""Client for managing a submitted compute task (a job)."""
|
|
78
|
+
|
|
79
|
+
def __init__(
|
|
80
|
+
self,
|
|
81
|
+
connector: APIConnector,
|
|
82
|
+
org_id: UUID,
|
|
83
|
+
topic: str,
|
|
84
|
+
task: str,
|
|
85
|
+
job_id: UUID,
|
|
86
|
+
result_type: type[T_Result] = dict,
|
|
87
|
+
) -> None:
|
|
88
|
+
"""
|
|
89
|
+
:param connector: The API connector to use.
|
|
90
|
+
:param org_id: The organization ID.
|
|
91
|
+
:param topic: The topic of the task.
|
|
92
|
+
:param task: The task to be executed.
|
|
93
|
+
:param job_id: The job ID.
|
|
94
|
+
:param result_type: The type to validate the result against.
|
|
95
|
+
"""
|
|
96
|
+
self._connector = connector
|
|
97
|
+
self._org_id = org_id
|
|
98
|
+
self._topic = topic
|
|
99
|
+
self._task = task
|
|
100
|
+
self._job_id = job_id
|
|
101
|
+
self._url = connector.base_url + f"compute/orgs/{self._org_id}/{self._topic}/{self._task}/{self._job_id}/status"
|
|
102
|
+
self._type_adapter = TypeAdapter(result_type)
|
|
103
|
+
self._mutex = asyncio.Lock()
|
|
104
|
+
self._results: T_Result | JobError | None = None
|
|
105
|
+
|
|
106
|
+
@property
|
|
107
|
+
def id(self) -> UUID:
|
|
108
|
+
"""The job id."""
|
|
109
|
+
return self._job_id
|
|
110
|
+
|
|
111
|
+
@property
|
|
112
|
+
def topic(self) -> str:
|
|
113
|
+
"""The topic of the task."""
|
|
114
|
+
return self._topic
|
|
115
|
+
|
|
116
|
+
@property
|
|
117
|
+
def task(self) -> str:
|
|
118
|
+
"""The task."""
|
|
119
|
+
return self._task
|
|
120
|
+
|
|
121
|
+
@property
|
|
122
|
+
def url(self) -> str:
|
|
123
|
+
"""The status URL of the job."""
|
|
124
|
+
return self._url
|
|
125
|
+
|
|
126
|
+
def __repr__(self) -> str:
|
|
127
|
+
return self.url
|
|
128
|
+
|
|
129
|
+
@staticmethod
|
|
130
|
+
def from_url(connector: APIConnector, url: str, result_type: type[T_Result] = dict) -> JobClient[T_Result]:
|
|
131
|
+
"""Create a job client from a status URL.
|
|
132
|
+
|
|
133
|
+
The URL hostname must match the connector base URL.
|
|
134
|
+
|
|
135
|
+
:param connector: The API connector to use.
|
|
136
|
+
:param url: The status URL of a submitted job.
|
|
137
|
+
:param result_type: The type to validate the result against.
|
|
138
|
+
|
|
139
|
+
:return: A client for managing the referenced job.
|
|
140
|
+
"""
|
|
141
|
+
if not url.startswith(connector.base_url):
|
|
142
|
+
raise ValueError("The job URL does not match the connector base URL.")
|
|
143
|
+
|
|
144
|
+
if match := RE_STATUS_URL.fullmatch(url.removeprefix(connector.base_url)):
|
|
145
|
+
path_params = match.groupdict()
|
|
146
|
+
for key in path_params:
|
|
147
|
+
if key.endswith("_id"):
|
|
148
|
+
try:
|
|
149
|
+
path_params[key] = UUID(path_params[key])
|
|
150
|
+
except ValueError:
|
|
151
|
+
raise ValueError(f"Invalid {key.removesuffix('_id')} ID in URL: {url}") from None
|
|
152
|
+
|
|
153
|
+
return JobClient(connector=connector, **path_params, result_type=result_type)
|
|
154
|
+
|
|
155
|
+
@staticmethod
|
|
156
|
+
async def submit(
|
|
157
|
+
connector: APIConnector,
|
|
158
|
+
org_id: UUID,
|
|
159
|
+
topic: str,
|
|
160
|
+
task: str,
|
|
161
|
+
parameters: Mapping[str, Any],
|
|
162
|
+
result_type: type[T_Result] = dict,
|
|
163
|
+
) -> JobClient[T_Result]:
|
|
164
|
+
"""Trigger an asynchronous task within a specific topic with the given parameters.
|
|
165
|
+
|
|
166
|
+
:param connector: The API connector to use.
|
|
167
|
+
:param topic: The topic of the task.
|
|
168
|
+
:param task: The task to be executed.
|
|
169
|
+
:param parameters: The parameters for the task.
|
|
170
|
+
:param result_type: The type to validate the result against.
|
|
171
|
+
|
|
172
|
+
:return: The job that was created.
|
|
173
|
+
|
|
174
|
+
:raises UnknownResponseError: If the Location header is missing or invalid.
|
|
175
|
+
"""
|
|
176
|
+
async with connector:
|
|
177
|
+
response = await TaskApi(connector).execute_task(
|
|
178
|
+
org_id=str(org_id),
|
|
179
|
+
topic=topic,
|
|
180
|
+
task=task,
|
|
181
|
+
task_parameters={"parameters": dict(parameters)},
|
|
182
|
+
)
|
|
183
|
+
|
|
184
|
+
# Location header is the status endpoint of the created job.
|
|
185
|
+
# i.e., compute/orgs/{org_id}/{topic}/{task}/{job_id}/status
|
|
186
|
+
try:
|
|
187
|
+
job_url = response.headers["Location"]
|
|
188
|
+
job_url = connector.base_url + job_url.removeprefix(connector.base_url).removeprefix("/")
|
|
189
|
+
return JobClient.from_url(connector, job_url, result_type)
|
|
190
|
+
except (KeyError, ValueError):
|
|
191
|
+
raise UnknownResponseError(
|
|
192
|
+
status=response.status, reason=response.reason, content=None, headers=response.headers
|
|
193
|
+
)
|
|
194
|
+
|
|
195
|
+
async def get_status(self) -> JobProgress:
|
|
196
|
+
"""Get the status of the job.
|
|
197
|
+
|
|
198
|
+
:return: The job progress.
|
|
199
|
+
"""
|
|
200
|
+
async with self._connector:
|
|
201
|
+
response = await JobApi(self._connector).get_job_status(
|
|
202
|
+
org_id=self._org_id,
|
|
203
|
+
topic=self._topic,
|
|
204
|
+
task=self._task,
|
|
205
|
+
job_id=self._job_id,
|
|
206
|
+
)
|
|
207
|
+
return JobProgress(
|
|
208
|
+
status=JobStatusEnum(response.status.value),
|
|
209
|
+
progress=response.progress,
|
|
210
|
+
message=response.message,
|
|
211
|
+
)
|
|
212
|
+
|
|
213
|
+
async def _get_results(self) -> T_Result | JobError:
|
|
214
|
+
"""Get the results of the job if they are not already cached.
|
|
215
|
+
|
|
216
|
+
The results are cached after the first successful call.
|
|
217
|
+
|
|
218
|
+
:return: The job results or error.
|
|
219
|
+
|
|
220
|
+
:raises UnknownResponseError: If the response or results fail validation.
|
|
221
|
+
:raises JobPendingError: If the job is still pending.
|
|
222
|
+
"""
|
|
223
|
+
async with self._mutex:
|
|
224
|
+
if self._results is None:
|
|
225
|
+
# Request the results from the API.
|
|
226
|
+
async with self._connector:
|
|
227
|
+
response = await JobApi(self._connector).get_job_results(
|
|
228
|
+
org_id=self._org_id,
|
|
229
|
+
topic=self._topic,
|
|
230
|
+
task=self._task,
|
|
231
|
+
job_id=self._job_id,
|
|
232
|
+
)
|
|
233
|
+
|
|
234
|
+
with _validating_pydantic_model(response):
|
|
235
|
+
job = CompletedJobResponse.model_validate_json(response.data)
|
|
236
|
+
|
|
237
|
+
if response.status == 202:
|
|
238
|
+
# The job is still pending, raise an error.
|
|
239
|
+
raise JobPendingError(url=self.url, status=job.status.value)
|
|
240
|
+
|
|
241
|
+
if error := job.error:
|
|
242
|
+
# The job failed, save the error.
|
|
243
|
+
self._results = JobError(
|
|
244
|
+
status=error.status,
|
|
245
|
+
reason=None,
|
|
246
|
+
content=error.model_dump(by_alias=True, exclude_unset=True, exclude_defaults=True),
|
|
247
|
+
headers=response.headers,
|
|
248
|
+
)
|
|
249
|
+
else:
|
|
250
|
+
# The job succeeded, deserialize and save the results.
|
|
251
|
+
with _validating_pydantic_model(response):
|
|
252
|
+
# Nitpick: job.results _may_ in fact be `None`, in which case the type adapter will
|
|
253
|
+
# raise ValidationError and trigger the error handling in the context manager.
|
|
254
|
+
# At the time of writing, it is unclear whether there are any valid cases where both
|
|
255
|
+
# the error and results are missing when the job is in a completed state.
|
|
256
|
+
self._results = self._type_adapter.validate_python(job.results)
|
|
257
|
+
|
|
258
|
+
# Return a copy of the cached results.
|
|
259
|
+
if isinstance(self._results, JobError):
|
|
260
|
+
return self._results.copy()
|
|
261
|
+
else:
|
|
262
|
+
return copy.deepcopy(self._results)
|
|
263
|
+
|
|
264
|
+
async def get_results(self) -> T_Result:
|
|
265
|
+
"""Get the results of the job.
|
|
266
|
+
|
|
267
|
+
:return: The results.
|
|
268
|
+
|
|
269
|
+
:raises UnknownResponseError: If the response or results fail validation.
|
|
270
|
+
:raises JobPendingError: If the job is still pending.
|
|
271
|
+
:raises JobError: If the job failed.
|
|
272
|
+
"""
|
|
273
|
+
if isinstance(results := await self._get_results(), JobError):
|
|
274
|
+
raise results.with_traceback(None)
|
|
275
|
+
return results
|
|
276
|
+
|
|
277
|
+
async def cancel(self) -> None:
|
|
278
|
+
"""Cancel the job."""
|
|
279
|
+
async with self._connector:
|
|
280
|
+
await JobApi(self._connector).cancel_job(
|
|
281
|
+
org_id=self._org_id,
|
|
282
|
+
topic=self._topic,
|
|
283
|
+
task=self._task,
|
|
284
|
+
job_id=self._job_id,
|
|
285
|
+
)
|
|
286
|
+
|
|
287
|
+
async def wait_for_results(
|
|
288
|
+
self, polling_interval_seconds: float = 0.5, retry: Retry | None = None, fb: IFeedback = NoFeedback
|
|
289
|
+
) -> T_Result:
|
|
290
|
+
"""Wait for the job to complete and return the results.
|
|
291
|
+
|
|
292
|
+
:param polling_interval_seconds: The interval in seconds between status checks.
|
|
293
|
+
:param retry: A Retry object with a wait strategy. If None, a default Retry is created.
|
|
294
|
+
:param fb: The feedback object to use.
|
|
295
|
+
|
|
296
|
+
:return: The results.
|
|
297
|
+
|
|
298
|
+
:raises UnknownResponseError: If the response or results fail validation.
|
|
299
|
+
:raises JobPendingError: If the job is still pending.
|
|
300
|
+
:raises JobError: If the job failed.
|
|
301
|
+
"""
|
|
302
|
+
if retry is None:
|
|
303
|
+
retry = Retry(logger)
|
|
304
|
+
|
|
305
|
+
latest_progress = 0.0
|
|
306
|
+
latest_message = "Waiting on remote job..."
|
|
307
|
+
|
|
308
|
+
while True:
|
|
309
|
+
async for handler in retry:
|
|
310
|
+
with handler.suppress_errors():
|
|
311
|
+
latest = await self.get_status()
|
|
312
|
+
|
|
313
|
+
if latest.status in (JobStatusEnum.succeeded, JobStatusEnum.failed, JobStatusEnum.cancelled):
|
|
314
|
+
break
|
|
315
|
+
|
|
316
|
+
# Task API returns progress as an integer between 0 and 100
|
|
317
|
+
latest_progress = latest_progress if latest.progress is None else latest.progress * 0.01
|
|
318
|
+
latest_message = latest_message if latest.message is None else latest.message
|
|
319
|
+
|
|
320
|
+
fb.progress(latest_progress, latest_message)
|
|
321
|
+
await asyncio.sleep(polling_interval_seconds)
|
|
322
|
+
|
|
323
|
+
fb.progress(1.0, "Fetching results...")
|
|
324
|
+
return await self.get_results()
|
evo/compute/data.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# Copyright © 2025 Bentley Systems, Incorporated
|
|
2
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
# you may not use this file except in compliance with the License.
|
|
4
|
+
# You may obtain a copy of the License at
|
|
5
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
7
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
8
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
9
|
+
# See the License for the specific language governing permissions and
|
|
10
|
+
# limitations under the License.
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
from dataclasses import dataclass
|
|
15
|
+
|
|
16
|
+
from .endpoints.models import JobStatusEnum
|
|
17
|
+
|
|
18
|
+
__all__ = [
|
|
19
|
+
"JobProgress",
|
|
20
|
+
"JobStatusEnum",
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@dataclass(frozen=True, kw_only=True)
|
|
25
|
+
class JobProgress:
|
|
26
|
+
status: JobStatusEnum
|
|
27
|
+
"""The status of the job."""
|
|
28
|
+
|
|
29
|
+
progress: int | None = None
|
|
30
|
+
"""A number between 0 and 100 representing the progress of the job."""
|
|
31
|
+
|
|
32
|
+
message: str | None = None
|
|
33
|
+
"""A message describing the current progress of the job."""
|
|
34
|
+
|
|
35
|
+
def __str__(self) -> str:
|
|
36
|
+
msg = f"[{self.status.value}]"
|
|
37
|
+
if self.progress is not None:
|
|
38
|
+
msg += f" {self.progress}%"
|
|
39
|
+
if self.message is not None:
|
|
40
|
+
msg += f" > {self.message}"
|
|
41
|
+
return msg
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Copyright © 2025 Bentley Systems, Incorporated
|
|
2
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
# you may not use this file except in compliance with the License.
|
|
4
|
+
# You may obtain a copy of the License at
|
|
5
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
7
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
8
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
9
|
+
# See the License for the specific language governing permissions and
|
|
10
|
+
# limitations under the License.
|
|
11
|
+
|
|
12
|
+
"""
|
|
13
|
+
Compute Task API
|
|
14
|
+
=============
|
|
15
|
+
|
|
16
|
+
Normally this code would be generated from an OpenAPI specification. However, the API specification for
|
|
17
|
+
the Compute Task API is new and not yet finalized. Therefore, this code is written against the intended API,
|
|
18
|
+
with some customisation as needed to make it work.
|
|
19
|
+
|
|
20
|
+
The client implementation should still abstract these details away from the user, so that the user can interact
|
|
21
|
+
with the API in a more user-friendly way, and so that this implementation can be changed without affecting the user.
|
|
22
|
+
|
|
23
|
+
This code is based on the OpenAPI specification for Compute Task API.
|
|
24
|
+
API version: 0.0.1
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
# Import endpoint apis.
|
|
28
|
+
from .api import JobApi, TaskApi
|
|
29
|
+
|
|
30
|
+
__all__ = [
|
|
31
|
+
"JobApi",
|
|
32
|
+
"TaskApi",
|
|
33
|
+
]
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Copyright © 2025 Bentley Systems, Incorporated
|
|
2
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
# you may not use this file except in compliance with the License.
|
|
4
|
+
# You may obtain a copy of the License at
|
|
5
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
7
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
8
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
9
|
+
# See the License for the specific language governing permissions and
|
|
10
|
+
# limitations under the License.
|
|
11
|
+
|
|
12
|
+
from .job_api import JobApi # noqa: F401
|
|
13
|
+
from .task_api import TaskApi # noqa: F401
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
# Copyright © 2025 Bentley Systems, Incorporated
|
|
2
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
# you may not use this file except in compliance with the License.
|
|
4
|
+
# You may obtain a copy of the License at
|
|
5
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
7
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
8
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
9
|
+
# See the License for the specific language governing permissions and
|
|
10
|
+
# limitations under the License.
|
|
11
|
+
|
|
12
|
+
"""
|
|
13
|
+
Compute Task API
|
|
14
|
+
=============
|
|
15
|
+
|
|
16
|
+
Normally this code would be generated from an OpenAPI specification. However, the API specification for
|
|
17
|
+
the Compute Task API is new and not yet finalized. Therefore, this code is written against the intended API,
|
|
18
|
+
with some customisation as needed to make it work.
|
|
19
|
+
|
|
20
|
+
The client implementation should still abstract these details away from the user, so that the user can interact
|
|
21
|
+
with the API in a more user-friendly way, and so that this implementation can be changed without affecting the user.
|
|
22
|
+
|
|
23
|
+
This code is based on the OpenAPI specification for Compute Task API.
|
|
24
|
+
API version: 0.0.1
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
from evo.common.connector import APIConnector
|
|
28
|
+
from evo.common.data import EmptyResponse, HTTPResponse, RequestMethod
|
|
29
|
+
|
|
30
|
+
from ..models import * # noqa: F403
|
|
31
|
+
|
|
32
|
+
__all__ = ["JobApi"]
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class JobApi:
|
|
36
|
+
"""API client for the job endpoint.
|
|
37
|
+
|
|
38
|
+
NOTE: This class is auto generated by OpenAPI Generator
|
|
39
|
+
Ref: https://openapi-generator.tech
|
|
40
|
+
|
|
41
|
+
Do not edit the class manually.
|
|
42
|
+
|
|
43
|
+
:param connector: Client for communicating with the API.
|
|
44
|
+
"""
|
|
45
|
+
|
|
46
|
+
def __init__(self, connector: APIConnector):
|
|
47
|
+
self.connector = connector
|
|
48
|
+
|
|
49
|
+
async def cancel_job(
|
|
50
|
+
self,
|
|
51
|
+
org_id: str,
|
|
52
|
+
topic: str,
|
|
53
|
+
task: str,
|
|
54
|
+
job_id: str,
|
|
55
|
+
additional_headers: dict[str, str] | None = None,
|
|
56
|
+
request_timeout: int | float | tuple[int | float, int | float] | None = None,
|
|
57
|
+
) -> EmptyResponse:
|
|
58
|
+
"""Cancels a specific job
|
|
59
|
+
|
|
60
|
+
Cancel a specific job, identified by the organization ID, topic, task, and job ID. The job's status is updated to 'canceling' and the job is stopped.
|
|
61
|
+
|
|
62
|
+
:param org_id: The organization identifier
|
|
63
|
+
Format: `uuid`
|
|
64
|
+
Example: `'org_id_example'`
|
|
65
|
+
:param topic: The compute topic
|
|
66
|
+
Example: `'topic_example'`
|
|
67
|
+
:param task: The compute task
|
|
68
|
+
Example: `'task_example'`
|
|
69
|
+
:param job_id: The job identifier
|
|
70
|
+
Format: `uuid`
|
|
71
|
+
Example: `'job_id_example'`
|
|
72
|
+
:param additional_headers: (optional) Additional headers to send with the request.
|
|
73
|
+
:param request_timeout: (optional) Timeout setting for this request. If one number is provided, it will be the
|
|
74
|
+
total request timeout. It can also be a pair (tuple) of (connection, read) timeouts.
|
|
75
|
+
|
|
76
|
+
:return: Returns the result object.
|
|
77
|
+
|
|
78
|
+
:raise evo.common.exceptions.BadRequestException: If the server responds with HTTP status 400.
|
|
79
|
+
:raise evo.common.exceptions.UnauthorizedException: If the server responds with HTTP status 401.
|
|
80
|
+
:raise evo.common.exceptions.ForbiddenException: If the server responds with HTTP status 403.
|
|
81
|
+
:raise evo.common.exceptions.NotFoundException: If the server responds with HTTP status 404.
|
|
82
|
+
:raise evo.common.exceptions.BaseTypedError: If the server responds with any other HTTP status between
|
|
83
|
+
400 and 599, and the body of the response contains a descriptive `type` parameter.
|
|
84
|
+
:raise evo.common.exceptions.EvoAPIException: If the server responds with any other HTTP status between 400
|
|
85
|
+
and 599, and the body of the response does not contain a `type` parameter.
|
|
86
|
+
:raise evo.common.exceptions.UnknownResponseError: For other HTTP status codes with no corresponding response
|
|
87
|
+
type in `response_types_map`.
|
|
88
|
+
""" # noqa: E501
|
|
89
|
+
# Prepare the path parameters.
|
|
90
|
+
_path_params = {
|
|
91
|
+
"org_id": org_id,
|
|
92
|
+
"topic": topic,
|
|
93
|
+
"task": task,
|
|
94
|
+
"job_id": job_id,
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
# Prepare the header parameters.
|
|
98
|
+
_header_params = {}
|
|
99
|
+
if additional_headers is not None:
|
|
100
|
+
_header_params.update(additional_headers)
|
|
101
|
+
|
|
102
|
+
# Define the collection formats.
|
|
103
|
+
_collection_formats = {}
|
|
104
|
+
|
|
105
|
+
_response_types_map = {
|
|
106
|
+
"204": EmptyResponse,
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return await self.connector.call_api(
|
|
110
|
+
method=RequestMethod.DELETE,
|
|
111
|
+
resource_path="/compute/orgs/{org_id}/{topic}/{task}/{job_id}",
|
|
112
|
+
path_params=_path_params,
|
|
113
|
+
header_params=_header_params,
|
|
114
|
+
collection_formats=_collection_formats,
|
|
115
|
+
response_types_map=_response_types_map,
|
|
116
|
+
request_timeout=request_timeout,
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
async def get_job_results(
|
|
120
|
+
self,
|
|
121
|
+
org_id: str,
|
|
122
|
+
topic: str,
|
|
123
|
+
task: str,
|
|
124
|
+
job_id: str,
|
|
125
|
+
additional_headers: dict[str, str] | None = None,
|
|
126
|
+
request_timeout: int | float | tuple[int | float, int | float] | None = None,
|
|
127
|
+
) -> HTTPResponse: # noqa: F405
|
|
128
|
+
"""Retrieves the results of a specific job
|
|
129
|
+
|
|
130
|
+
Get the results of a specific job, identified by the organization ID, topic, task, and job ID. The job's status is returned in the response, along with either the results or an error object, depending on the status of the job. If the job is ongoing, the response includes links to the job's cancellation endpoint and detailed status endpoint.
|
|
131
|
+
|
|
132
|
+
:param org_id: The organization identifier
|
|
133
|
+
Format: `uuid`
|
|
134
|
+
Example: `'org_id_example'`
|
|
135
|
+
:param topic: The compute topic
|
|
136
|
+
Example: `'topic_example'`
|
|
137
|
+
:param task: The compute task
|
|
138
|
+
Example: `'task_example'`
|
|
139
|
+
:param job_id: The job identifier
|
|
140
|
+
Format: `uuid`
|
|
141
|
+
Example: `'job_id_example'`
|
|
142
|
+
:param additional_headers: (optional) Additional headers to send with the request.
|
|
143
|
+
:param request_timeout: (optional) Timeout setting for this request. If one number is provided, it will be the
|
|
144
|
+
total request timeout. It can also be a pair (tuple) of (connection, read) timeouts.
|
|
145
|
+
|
|
146
|
+
:return: Returns the result object.
|
|
147
|
+
|
|
148
|
+
:raise evo.common.exceptions.BadRequestException: If the server responds with HTTP status 400.
|
|
149
|
+
:raise evo.common.exceptions.UnauthorizedException: If the server responds with HTTP status 401.
|
|
150
|
+
:raise evo.common.exceptions.ForbiddenException: If the server responds with HTTP status 403.
|
|
151
|
+
:raise evo.common.exceptions.NotFoundException: If the server responds with HTTP status 404.
|
|
152
|
+
:raise evo.common.exceptions.BaseTypedError: If the server responds with any other HTTP status between
|
|
153
|
+
400 and 599, and the body of the response contains a descriptive `type` parameter.
|
|
154
|
+
:raise evo.common.exceptions.EvoAPIException: If the server responds with any other HTTP status between 400
|
|
155
|
+
and 599, and the body of the response does not contain a `type` parameter.
|
|
156
|
+
:raise evo.common.exceptions.UnknownResponseError: For other HTTP status codes with no corresponding response
|
|
157
|
+
type in `response_types_map`.
|
|
158
|
+
""" # noqa: E501
|
|
159
|
+
# Prepare the path parameters.
|
|
160
|
+
_path_params = {
|
|
161
|
+
"org_id": org_id,
|
|
162
|
+
"topic": topic,
|
|
163
|
+
"task": task,
|
|
164
|
+
"job_id": job_id,
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
# Prepare the header parameters.
|
|
168
|
+
_header_params = {
|
|
169
|
+
"Accept": "application/json",
|
|
170
|
+
}
|
|
171
|
+
if additional_headers is not None:
|
|
172
|
+
_header_params.update(additional_headers)
|
|
173
|
+
|
|
174
|
+
# Define the collection formats.
|
|
175
|
+
_collection_formats = {}
|
|
176
|
+
|
|
177
|
+
_response_types_map = {
|
|
178
|
+
# Get the raw response so we can include headers if the job failed.
|
|
179
|
+
"200": HTTPResponse,
|
|
180
|
+
"202": HTTPResponse,
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return await self.connector.call_api(
|
|
184
|
+
method=RequestMethod.GET,
|
|
185
|
+
resource_path="/compute/orgs/{org_id}/{topic}/{task}/{job_id}",
|
|
186
|
+
path_params=_path_params,
|
|
187
|
+
header_params=_header_params,
|
|
188
|
+
collection_formats=_collection_formats,
|
|
189
|
+
response_types_map=_response_types_map,
|
|
190
|
+
request_timeout=request_timeout,
|
|
191
|
+
)
|
|
192
|
+
|
|
193
|
+
async def get_job_status(
|
|
194
|
+
self,
|
|
195
|
+
org_id: str,
|
|
196
|
+
topic: str,
|
|
197
|
+
task: str,
|
|
198
|
+
job_id: str,
|
|
199
|
+
additional_headers: dict[str, str] | None = None,
|
|
200
|
+
request_timeout: int | float | tuple[int | float, int | float] | None = None,
|
|
201
|
+
) -> JobStatusResponse: # noqa: F405
|
|
202
|
+
"""Retrieves the status of a specific job
|
|
203
|
+
|
|
204
|
+
Get the status of a specific job, identified by the organization ID, topic, task, and job ID. The job's status is returned in the response, along with a progress indicator, a message, and an error object, if applicable. If the job is ongoing, the response includes links to the job's cancellation endpoint.
|
|
205
|
+
|
|
206
|
+
:param org_id: The organization identifier
|
|
207
|
+
Format: `uuid`
|
|
208
|
+
Example: `'org_id_example'`
|
|
209
|
+
:param topic: The compute topic
|
|
210
|
+
Example: `'topic_example'`
|
|
211
|
+
:param task: The compute task
|
|
212
|
+
Example: `'task_example'`
|
|
213
|
+
:param job_id: The job identifier
|
|
214
|
+
Format: `uuid`
|
|
215
|
+
Example: `'job_id_example'`
|
|
216
|
+
:param additional_headers: (optional) Additional headers to send with the request.
|
|
217
|
+
:param request_timeout: (optional) Timeout setting for this request. If one number is provided, it will be the
|
|
218
|
+
total request timeout. It can also be a pair (tuple) of (connection, read) timeouts.
|
|
219
|
+
|
|
220
|
+
:return: Returns the result object.
|
|
221
|
+
|
|
222
|
+
:raise evo.common.exceptions.BadRequestException: If the server responds with HTTP status 400.
|
|
223
|
+
:raise evo.common.exceptions.UnauthorizedException: If the server responds with HTTP status 401.
|
|
224
|
+
:raise evo.common.exceptions.ForbiddenException: If the server responds with HTTP status 403.
|
|
225
|
+
:raise evo.common.exceptions.NotFoundException: If the server responds with HTTP status 404.
|
|
226
|
+
:raise evo.common.exceptions.BaseTypedError: If the server responds with any other HTTP status between
|
|
227
|
+
400 and 599, and the body of the response contains a descriptive `type` parameter.
|
|
228
|
+
:raise evo.common.exceptions.EvoAPIException: If the server responds with any other HTTP status between 400
|
|
229
|
+
and 599, and the body of the response does not contain a `type` parameter.
|
|
230
|
+
:raise evo.common.exceptions.UnknownResponseError: For other HTTP status codes with no corresponding response
|
|
231
|
+
type in `response_types_map`.
|
|
232
|
+
""" # noqa: E501
|
|
233
|
+
# Prepare the path parameters.
|
|
234
|
+
_path_params = {
|
|
235
|
+
"org_id": org_id,
|
|
236
|
+
"topic": topic,
|
|
237
|
+
"task": task,
|
|
238
|
+
"job_id": job_id,
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
# Prepare the header parameters.
|
|
242
|
+
_header_params = {
|
|
243
|
+
"Accept": "application/json",
|
|
244
|
+
}
|
|
245
|
+
if additional_headers is not None:
|
|
246
|
+
_header_params.update(additional_headers)
|
|
247
|
+
|
|
248
|
+
# Define the collection formats.
|
|
249
|
+
_collection_formats = {}
|
|
250
|
+
|
|
251
|
+
_response_types_map = {
|
|
252
|
+
"200": JobStatusResponse, # noqa: F405
|
|
253
|
+
"202": JobStatusResponse, # noqa: F405
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
return await self.connector.call_api(
|
|
257
|
+
method=RequestMethod.GET,
|
|
258
|
+
resource_path="/compute/orgs/{org_id}/{topic}/{task}/{job_id}/status",
|
|
259
|
+
path_params=_path_params,
|
|
260
|
+
header_params=_header_params,
|
|
261
|
+
collection_formats=_collection_formats,
|
|
262
|
+
response_types_map=_response_types_map,
|
|
263
|
+
request_timeout=request_timeout,
|
|
264
|
+
)
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
# Copyright © 2025 Bentley Systems, Incorporated
|
|
2
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
# you may not use this file except in compliance with the License.
|
|
4
|
+
# You may obtain a copy of the License at
|
|
5
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
7
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
8
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
9
|
+
# See the License for the specific language governing permissions and
|
|
10
|
+
# limitations under the License.
|
|
11
|
+
|
|
12
|
+
"""
|
|
13
|
+
Compute Task API
|
|
14
|
+
=============
|
|
15
|
+
|
|
16
|
+
Normally this code would be generated from an OpenAPI specification. However, the API specification for
|
|
17
|
+
the Compute Task API is new and not yet finalized. Therefore, this code is written against the intended API,
|
|
18
|
+
with some customisation as needed to make it work.
|
|
19
|
+
|
|
20
|
+
The client implementation should still abstract these details away from the user, so that the user can interact
|
|
21
|
+
with the API in a more user-friendly way, and so that this implementation can be changed without affecting the user.
|
|
22
|
+
|
|
23
|
+
This code is based on the OpenAPI specification for Compute Task API.
|
|
24
|
+
API version: 0.0.1
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
from evo.common.connector import APIConnector
|
|
28
|
+
from evo.common.data import EmptyResponse, RequestMethod
|
|
29
|
+
|
|
30
|
+
from ..models import * # noqa: F403
|
|
31
|
+
|
|
32
|
+
__all__ = ["TaskApi"]
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class TaskApi:
|
|
36
|
+
"""API client for the task endpoint.
|
|
37
|
+
|
|
38
|
+
NOTE: This class is auto generated by OpenAPI Generator
|
|
39
|
+
Ref: https://openapi-generator.tech
|
|
40
|
+
|
|
41
|
+
Do not edit the class manually.
|
|
42
|
+
|
|
43
|
+
:param connector: Client for communicating with the API.
|
|
44
|
+
"""
|
|
45
|
+
|
|
46
|
+
def __init__(self, connector: APIConnector):
|
|
47
|
+
self.connector = connector
|
|
48
|
+
|
|
49
|
+
async def execute_task(
|
|
50
|
+
self,
|
|
51
|
+
org_id: str,
|
|
52
|
+
topic: str,
|
|
53
|
+
task: str,
|
|
54
|
+
task_parameters: dict | None = None,
|
|
55
|
+
additional_headers: dict[str, str] | None = None,
|
|
56
|
+
request_timeout: int | float | tuple[int | float, int | float] | None = None,
|
|
57
|
+
) -> EmptyResponse:
|
|
58
|
+
"""Triggers an asynchronous execution of a task
|
|
59
|
+
|
|
60
|
+
Trigger an asynchronous task within a specific topic for a designated organization. The task, topic, and organization ID are supplied as path parameters. A JSON request body, referencing the **dict** schema and containing task-specific parameters, is required for this operation. Upon successful start, a 303 response is returned. The URL of the status endpoint for the newly created job is indicated in the Location header of the response.
|
|
61
|
+
|
|
62
|
+
:param org_id: The organization identifier
|
|
63
|
+
Format: `uuid`
|
|
64
|
+
Example: `'org_id_example'`
|
|
65
|
+
:param topic: The compute topic
|
|
66
|
+
Example: `'topic_example'`
|
|
67
|
+
:param task: The compute task
|
|
68
|
+
Example: `'task_example'`
|
|
69
|
+
:param task_parameters: (optional)
|
|
70
|
+
:param additional_headers: (optional) Additional headers to send with the request.
|
|
71
|
+
:param request_timeout: (optional) Timeout setting for this request. If one number is provided, it will be the
|
|
72
|
+
total request timeout. It can also be a pair (tuple) of (connection, read) timeouts.
|
|
73
|
+
|
|
74
|
+
:return: Returns the result object.
|
|
75
|
+
|
|
76
|
+
:raise evo.common.exceptions.BadRequestException: If the server responds with HTTP status 400.
|
|
77
|
+
:raise evo.common.exceptions.UnauthorizedException: If the server responds with HTTP status 401.
|
|
78
|
+
:raise evo.common.exceptions.ForbiddenException: If the server responds with HTTP status 403.
|
|
79
|
+
:raise evo.common.exceptions.NotFoundException: If the server responds with HTTP status 404.
|
|
80
|
+
:raise evo.common.exceptions.BaseTypedError: If the server responds with any other HTTP status between
|
|
81
|
+
400 and 599, and the body of the response contains a descriptive `type` parameter.
|
|
82
|
+
:raise evo.common.exceptions.EvoAPIException: If the server responds with any other HTTP status between 400
|
|
83
|
+
and 599, and the body of the response does not contain a `type` parameter.
|
|
84
|
+
:raise evo.common.exceptions.UnknownResponseError: For other HTTP status codes with no corresponding response
|
|
85
|
+
type in `response_types_map`.
|
|
86
|
+
""" # noqa: E501
|
|
87
|
+
# Prepare the path parameters.
|
|
88
|
+
_path_params = {
|
|
89
|
+
"org_id": org_id,
|
|
90
|
+
"topic": topic,
|
|
91
|
+
"task": task,
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
# Prepare the header parameters.
|
|
95
|
+
_header_params = {
|
|
96
|
+
"Content-Type": "application/json",
|
|
97
|
+
}
|
|
98
|
+
if additional_headers is not None:
|
|
99
|
+
_header_params.update(additional_headers)
|
|
100
|
+
|
|
101
|
+
# Define the collection formats.
|
|
102
|
+
_collection_formats = {}
|
|
103
|
+
|
|
104
|
+
_response_types_map = {
|
|
105
|
+
"303": EmptyResponse,
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return await self.connector.call_api(
|
|
109
|
+
method=RequestMethod.POST,
|
|
110
|
+
resource_path="/compute/orgs/{org_id}/{topic}/{task}",
|
|
111
|
+
path_params=_path_params,
|
|
112
|
+
header_params=_header_params,
|
|
113
|
+
body=task_parameters,
|
|
114
|
+
collection_formats=_collection_formats,
|
|
115
|
+
response_types_map=_response_types_map,
|
|
116
|
+
request_timeout=request_timeout,
|
|
117
|
+
)
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# Copyright © 2025 Bentley Systems, Incorporated
|
|
2
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
# you may not use this file except in compliance with the License.
|
|
4
|
+
# You may obtain a copy of the License at
|
|
5
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
7
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
8
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
9
|
+
# See the License for the specific language governing permissions and
|
|
10
|
+
# limitations under the License.
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
from enum import Enum
|
|
15
|
+
|
|
16
|
+
from pydantic import BaseModel, ConfigDict, Field, StrictInt, StrictStr
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class JobStatusEnum(Enum):
|
|
20
|
+
"""
|
|
21
|
+
Enum representing the status of a job.
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
requested = "requested"
|
|
25
|
+
in_progress = "in progress"
|
|
26
|
+
succeeded = "succeeded"
|
|
27
|
+
failed = "failed"
|
|
28
|
+
cancelling = "cancelling"
|
|
29
|
+
cancelled = "cancelled"
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class Error(BaseModel):
|
|
33
|
+
model_config = ConfigDict(
|
|
34
|
+
extra="allow",
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
status: StrictInt
|
|
38
|
+
"""The status code of the error."""
|
|
39
|
+
|
|
40
|
+
type_: StrictStr = Field(alias="type")
|
|
41
|
+
"""The type of the error."""
|
|
42
|
+
|
|
43
|
+
title: StrictStr
|
|
44
|
+
"""The title of the error."""
|
|
45
|
+
|
|
46
|
+
detail: StrictStr | None = None
|
|
47
|
+
"""A message describing the error."""
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
class JobStatusResponse(BaseModel):
|
|
51
|
+
model_config = ConfigDict(
|
|
52
|
+
extra="allow",
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
status: JobStatusEnum
|
|
56
|
+
"""The status of the job."""
|
|
57
|
+
|
|
58
|
+
progress: StrictInt | None = Field(None, ge=0, le=100)
|
|
59
|
+
"""A number between 0 and 100 representing the progress of the job."""
|
|
60
|
+
|
|
61
|
+
message: StrictStr | None = None
|
|
62
|
+
"""A message describing the current progress of the job."""
|
|
63
|
+
|
|
64
|
+
error: Error | None = None
|
|
65
|
+
"""An error that occurred during the job."""
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
class CompletedJobResponse(BaseModel):
|
|
69
|
+
model_config = ConfigDict(
|
|
70
|
+
extra="allow",
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
status: JobStatusEnum
|
|
74
|
+
"""The status of the job."""
|
|
75
|
+
|
|
76
|
+
results: dict | None = None
|
|
77
|
+
"""The results of the job."""
|
|
78
|
+
|
|
79
|
+
error: Error | None = None
|
|
80
|
+
"""An error that occurred during the job."""
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Copyright © 2025 Bentley Systems, Incorporated
|
|
2
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
# you may not use this file except in compliance with the License.
|
|
4
|
+
# You may obtain a copy of the License at
|
|
5
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
7
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
8
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
9
|
+
# See the License for the specific language governing permissions and
|
|
10
|
+
# limitations under the License.
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
import copy
|
|
15
|
+
|
|
16
|
+
from evo.common.exceptions import BaseTypedError, EvoClientException
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class JobError(BaseTypedError):
|
|
20
|
+
"""Raised when a job fails."""
|
|
21
|
+
|
|
22
|
+
def copy(self) -> JobError:
|
|
23
|
+
"""Return a copy of the error.
|
|
24
|
+
|
|
25
|
+
Job result responses are cached so that they can be retrieved multiple times without
|
|
26
|
+
re-fetching. This method is used to create a copy of an error result so that it can be
|
|
27
|
+
raised from a cached copy without modifying the original.
|
|
28
|
+
|
|
29
|
+
:return: A copy of the error.
|
|
30
|
+
"""
|
|
31
|
+
return JobError(
|
|
32
|
+
status=self.status,
|
|
33
|
+
reason=self.reason,
|
|
34
|
+
content=copy.deepcopy(self.content),
|
|
35
|
+
headers=self.headers.copy(),
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class JobPendingError(EvoClientException):
|
|
40
|
+
"""Raised when results are requested but the job is still pending."""
|
|
41
|
+
|
|
42
|
+
def __init__(self, url: str, status: str) -> None:
|
|
43
|
+
super().__init__(f"Job at {url} is still pending with status: {status}")
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: evo-compute
|
|
3
|
+
Version: 0.0.1rc0
|
|
4
|
+
Project-URL: Source, https://github.com/SeequentEvo/evo-python-sdk
|
|
5
|
+
Project-URL: Tracker, https://github.com/SeequentEvo/evo-python-sdk/issues
|
|
6
|
+
Project-URL: Homepage, https://www.seequent.com/
|
|
7
|
+
Project-URL: Documentation, https://developer.seequent.com/
|
|
8
|
+
Author-email: Seequent <support@seequent.com>
|
|
9
|
+
License-File: LICENSE.md
|
|
10
|
+
Requires-Python: >=3.10
|
|
11
|
+
Requires-Dist: evo-sdk-common
|
|
12
|
+
Requires-Dist: pydantic>=2
|
|
13
|
+
Provides-Extra: aiohttp
|
|
14
|
+
Requires-Dist: evo-sdk-common[aiohttp]; extra == 'aiohttp'
|
|
15
|
+
Provides-Extra: notebooks
|
|
16
|
+
Requires-Dist: evo-sdk-common[notebooks]; extra == 'notebooks'
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
|
|
19
|
+
<p align="center"><a href="https://seequent.com" target="_blank"><picture><source media="(prefers-color-scheme: dark)" srcset="https://developer.seequent.com/img/seequent-logo-dark.svg" alt="Seequent logo" width="400" /><img src="https://developer.seequent.com/img/seequent-logo.svg" alt="Seequent logo" width="400" /></picture></a></p>
|
|
20
|
+
<p align="center">
|
|
21
|
+
<a href="https://pypi.org/project/evo-compute/"><img alt="PyPI - Version" src="https://img.shields.io/pypi/v/evo-compute" /></a>
|
|
22
|
+
<a href="https://github.com/SeequentEvo/evo-python-sdk/actions/workflows/run-all-tests.yaml"><img src="https://github.com/SeequentEvo/evo-python-sdk/actions/workflows/run-all-tests.yaml/badge.svg" alt="" /></a>
|
|
23
|
+
</p>
|
|
24
|
+
<p align="center">
|
|
25
|
+
<a href="https://developer.seequent.com/" target="_blank">Seequent Developer Portal</a>
|
|
26
|
+
• <a href="https://community.seequent.com/group/19-evo" target="_blank">Seequent Community</a>
|
|
27
|
+
• <a href="https://seequent.com" target="_blank">Seequent website</a>
|
|
28
|
+
</p>
|
|
29
|
+
|
|
30
|
+
# Evo Compute Task Client
|
|
31
|
+
|
|
32
|
+
The Compute Task API provides the ability to execute computation tasks in Evo that require variable, on-demand processing power. Building the Compute Task API into your application can enable fast processing of long running, or resource intensive operations, without depending on the end user's physical hardware.
|
|
33
|
+
|
|
34
|
+
Tasks are created, triggering a job to be executed asynchronously within a specific topic for your organization, and can be monitored throughout their execution lifecycle.
|
|
35
|
+
|
|
36
|
+
## Pre-requisites
|
|
37
|
+
|
|
38
|
+
* Python ^3.10
|
|
39
|
+
* An [application registered in Bentley](https://developer.bentley.com/register/?product=seequent-evo)
|
|
40
|
+
|
|
41
|
+
## Installation
|
|
42
|
+
|
|
43
|
+
```shell
|
|
44
|
+
pip install evo-compute
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Usage
|
|
48
|
+
|
|
49
|
+
See [the evo-sdk-common documentation](https://github.com/SeequentEvo/evo-python-sdk/blob/main/packages/evo-sdk-common/README.md)
|
|
50
|
+
for information on how to authenticate, then select the organisation, hub and workspace that you would like to use.
|
|
51
|
+
|
|
52
|
+
### Interacting with the Compute Task API
|
|
53
|
+
|
|
54
|
+
To get up and running quickly with the Evo Compute Task SDK, start by configuring your
|
|
55
|
+
[environment and API connector](https://github.com/SeequentEvo/evo-python-sdk/blob/main/packages/evo-sdk-common/docs/quickstart.md).
|
|
56
|
+
|
|
57
|
+
For some interactive Jupyter notebook examples, see the [examples folder](https://github.com/SeequentEvo/evo-python-sdk/tree/main/packages/evo-compute/docs/examples).
|
|
58
|
+
|
|
59
|
+
## Contributing
|
|
60
|
+
|
|
61
|
+
For instructions on contributing to the development of this library, please refer to the [evo-python-sdk documentation](https://github.com/seequentevo/evo-python-sdk).
|
|
62
|
+
|
|
63
|
+
## License
|
|
64
|
+
|
|
65
|
+
The Python SDK for Evo is open source and licensed under the [Apache 2.0 license.](https://github.com/SeequentEvo/evo-python-sdk/tree/main/packages/evo-compute/./LICENSE.md).
|
|
66
|
+
|
|
67
|
+
Copyright © 2025 Bentley Systems, Incorporated.
|
|
68
|
+
|
|
69
|
+
Licensed under the Apache License, Version 2.0 (the "License").
|
|
70
|
+
You may obtain a copy of the License at
|
|
71
|
+
|
|
72
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
73
|
+
|
|
74
|
+
Unless required by applicable law or agreed to in writing, software
|
|
75
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
76
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
77
|
+
See the License for the specific language governing permissions and
|
|
78
|
+
limitations under the License.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
evo/compute/__init__.py,sha256=SPABkv0ymxi1td8sOw3tXvp_DIMDkC_J-EOo2BhT-Rw,748
|
|
2
|
+
evo/compute/client.py,sha256=lEDK-T7D1Y0oLMNRUuPPrAyTLNKLVL5Ipy4BVPKLw6E,12074
|
|
3
|
+
evo/compute/data.py,sha256=D9-y1fXmLor4a7DskaRbfBGc1YkG7eVEc7ZqfmQfrlE,1337
|
|
4
|
+
evo/compute/exceptions.py,sha256=nIG2yo-KlD5FShQgIHqOG5X1IzUArMkqA4xpZ16ClJI,1611
|
|
5
|
+
evo/compute/endpoints/__init__.py,sha256=GCELPWeS3aWBolT9KmYzPK_qgvcWGX1El1gL2lyMuso,1327
|
|
6
|
+
evo/compute/endpoints/models.py,sha256=_SIcOAo9aql-np47a4_3Wlk9bMjmI-AgvwnfcBM3RX0,2135
|
|
7
|
+
evo/compute/endpoints/api/__init__.py,sha256=yePi-ECRk36J3cCXzEd8TmCVmytSsMh_pZjK_YxbDwg,687
|
|
8
|
+
evo/compute/endpoints/api/job_api.py,sha256=xaVTR_NfT4qaPYkou30YpDFEQH5uEyAoA4dd9fA3AjA,11865
|
|
9
|
+
evo/compute/endpoints/api/task_api.py,sha256=uD_7DjTCqSkbjpQh8jstB4IjZ50H1fr2X2xEtVz_YrE,5199
|
|
10
|
+
evo_compute-0.0.1rc0.dist-info/METADATA,sha256=caQ_tpWbuF9rrUwfsVguZ_fMAHEVEMAwNUhXh8JpZLE,3963
|
|
11
|
+
evo_compute-0.0.1rc0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
12
|
+
evo_compute-0.0.1rc0.dist-info/licenses/LICENSE.md,sha256=HcFeRdOI-VP5WPEymQerlwLvEj2z_1Yh66RkN-wN7Oc,10778
|
|
13
|
+
evo_compute-0.0.1rc0.dist-info/RECORD,,
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
Copyright © 2025 Bentley Systems, Incorporated.
|
|
2
|
+
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License.
|
|
5
|
+
You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
See the License for the specific language governing permissions and
|
|
13
|
+
limitations under the License.
|
|
14
|
+
|
|
15
|
+
Apache License
|
|
16
|
+
Version 2.0, January 2004
|
|
17
|
+
http://www.apache.org/licenses/
|
|
18
|
+
|
|
19
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
20
|
+
|
|
21
|
+
1. Definitions.
|
|
22
|
+
|
|
23
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
24
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
25
|
+
|
|
26
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
27
|
+
the copyright owner that is granting the License.
|
|
28
|
+
|
|
29
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
30
|
+
other entities that control, are controlled by, or are under common
|
|
31
|
+
control with that entity. For the purposes of this definition,
|
|
32
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
33
|
+
direction or management of such entity, whether by contract or
|
|
34
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
35
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
36
|
+
|
|
37
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
38
|
+
exercising permissions granted by this License.
|
|
39
|
+
|
|
40
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
41
|
+
including but not limited to software source code, documentation
|
|
42
|
+
source, and configuration files.
|
|
43
|
+
|
|
44
|
+
"Object" form shall mean any form resulting from mechanical
|
|
45
|
+
transformation or translation of a Source form, including but
|
|
46
|
+
not limited to compiled object code, generated documentation,
|
|
47
|
+
and conversions to other media types.
|
|
48
|
+
|
|
49
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
50
|
+
Object form, made available under the License, as indicated by a
|
|
51
|
+
copyright notice that is included in or attached to the work
|
|
52
|
+
(an example is provided in the Appendix below).
|
|
53
|
+
|
|
54
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
55
|
+
form, that is based on (or derived from) the Work and for which the
|
|
56
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
57
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
58
|
+
of this License, Derivative Works shall not include works that remain
|
|
59
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
60
|
+
the Work and Derivative Works thereof.
|
|
61
|
+
|
|
62
|
+
"Contribution" shall mean any work of authorship, including
|
|
63
|
+
the original version of the Work and any modifications or additions
|
|
64
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
65
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
66
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
67
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
68
|
+
means any form of electronic, verbal, or written communication sent
|
|
69
|
+
to the Licensor or its representatives, including but not limited to
|
|
70
|
+
communication on electronic mailing lists, source code control systems,
|
|
71
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
72
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
73
|
+
excluding communication that is conspicuously marked or otherwise
|
|
74
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
75
|
+
|
|
76
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
77
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
78
|
+
subsequently incorporated within the Work.
|
|
79
|
+
|
|
80
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
81
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
82
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
83
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
84
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
85
|
+
Work and such Derivative Works in Source or Object form.
|
|
86
|
+
|
|
87
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
88
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
89
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
90
|
+
(except as stated in this section) patent license to make, have made,
|
|
91
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
92
|
+
where such license applies only to those patent claims licensable
|
|
93
|
+
by such Contributor that are necessarily infringed by their
|
|
94
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
95
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
96
|
+
institute patent litigation against any entity (including a
|
|
97
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
98
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
99
|
+
or contributory patent infringement, then any patent licenses
|
|
100
|
+
granted to You under this License for that Work shall terminate
|
|
101
|
+
as of the date such litigation is filed.
|
|
102
|
+
|
|
103
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
104
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
105
|
+
modifications, and in Source or Object form, provided that You
|
|
106
|
+
meet the following conditions:
|
|
107
|
+
|
|
108
|
+
(a) You must give any other recipients of the Work or
|
|
109
|
+
Derivative Works a copy of this License; and
|
|
110
|
+
|
|
111
|
+
(b) You must cause any modified files to carry prominent notices
|
|
112
|
+
stating that You changed the files; and
|
|
113
|
+
|
|
114
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
115
|
+
that You distribute, all copyright, patent, trademark, and
|
|
116
|
+
attribution notices from the Source form of the Work,
|
|
117
|
+
excluding those notices that do not pertain to any part of
|
|
118
|
+
the Derivative Works; and
|
|
119
|
+
|
|
120
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
121
|
+
distribution, then any Derivative Works that You distribute must
|
|
122
|
+
include a readable copy of the attribution notices contained
|
|
123
|
+
within such NOTICE file, excluding those notices that do not
|
|
124
|
+
pertain to any part of the Derivative Works, in at least one
|
|
125
|
+
of the following places: within a NOTICE text file distributed
|
|
126
|
+
as part of the Derivative Works; within the Source form or
|
|
127
|
+
documentation, if provided along with the Derivative Works; or,
|
|
128
|
+
within a display generated by the Derivative Works, if and
|
|
129
|
+
wherever such third-party notices normally appear. The contents
|
|
130
|
+
of the NOTICE file are for informational purposes only and
|
|
131
|
+
do not modify the License. You may add Your own attribution
|
|
132
|
+
notices within Derivative Works that You distribute, alongside
|
|
133
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
134
|
+
that such additional attribution notices cannot be construed
|
|
135
|
+
as modifying the License.
|
|
136
|
+
|
|
137
|
+
You may add Your own copyright statement to Your modifications and
|
|
138
|
+
may provide additional or different license terms and conditions
|
|
139
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
140
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
141
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
142
|
+
the conditions stated in this License.
|
|
143
|
+
|
|
144
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
145
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
146
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
147
|
+
this License, without any additional terms or conditions.
|
|
148
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
149
|
+
the terms of any separate license agreement you may have executed
|
|
150
|
+
with Licensor regarding such Contributions.
|
|
151
|
+
|
|
152
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
153
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
154
|
+
except as required for reasonable and customary use in describing the
|
|
155
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
156
|
+
|
|
157
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
158
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
159
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
160
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
161
|
+
implied, including, without limitation, any warranties or conditions
|
|
162
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
163
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
164
|
+
appropriateness of using or redistributing the Work and assume any
|
|
165
|
+
risks associated with Your exercise of permissions under this License.
|
|
166
|
+
|
|
167
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
168
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
169
|
+
unless required by applicable law (such as deliberate and grossly
|
|
170
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
171
|
+
liable to You for damages, including any direct, indirect, special,
|
|
172
|
+
incidental, or consequential damages of any character arising as a
|
|
173
|
+
result of this License or out of the use or inability to use the
|
|
174
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
175
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
176
|
+
other commercial damages or losses), even if such Contributor
|
|
177
|
+
has been advised of the possibility of such damages.
|
|
178
|
+
|
|
179
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
180
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
181
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
182
|
+
or other liability obligations and/or rights consistent with this
|
|
183
|
+
License. However, in accepting such obligations, You may act only
|
|
184
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
185
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
186
|
+
defend, and hold each Contributor harmless for any liability
|
|
187
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
188
|
+
of your accepting any such warranty or additional liability.
|
|
189
|
+
|
|
190
|
+
END OF TERMS AND CONDITIONS
|