codeocean 0.1.5__tar.gz → 0.1.7__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.
@@ -1,6 +1,14 @@
1
1
  CHANGELOG
2
2
  =========
3
3
 
4
+ ## 0.1.7 (2024-10-17)
5
+
6
+ - [#14](https://github.com/codeocean/codeocean-sdk-python/pull/14) feat: Add an optional timeout parameter to polling while loops
7
+
8
+ ## 0.1.6 (2024-10-15)
9
+
10
+ - [#13](https://github.com/codeocean/codeocean-sdk-python/pull/13) feat: makes polling interval configurable
11
+
4
12
  ## 0.1.5 (2024-08-08)
5
13
 
6
14
  - [#10](https://github.com/codeocean/codeocean-sdk-python/pull/10) fix: Provenance optional fields
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: codeocean
3
- Version: 0.1.5
3
+ Version: 0.1.7
4
4
  Summary: Code Ocean Python SDK
5
5
  Project-URL: Homepage, https://github.com/codeocean/codeocean-sdk-python
6
6
  Project-URL: Issues, https://github.com/codeocean/codeocean-sdk-python/issues
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "codeocean"
7
- version = "0.1.5"
7
+ version = "0.1.7"
8
8
  authors = [
9
9
  { name="Code Ocean", email="dev@codeocean.com" },
10
10
  ]
@@ -4,7 +4,7 @@ from dataclasses import dataclass
4
4
  from dataclasses_json import dataclass_json
5
5
  from requests_toolbelt.sessions import BaseUrlSession
6
6
  from typing import Optional
7
- from time import sleep
7
+ from time import sleep, time
8
8
 
9
9
  from codeocean.enum import StrEnum
10
10
 
@@ -141,17 +141,40 @@ class Computations:
141
141
 
142
142
  return Computation.from_dict(res.json())
143
143
 
144
- def wait_until_completed(self, computation: Computation) -> Computation:
144
+ def wait_until_completed(
145
+ self,
146
+ computation: Computation,
147
+ polling_interval: float = 5,
148
+ timeout: Optional[float] = None,
149
+ ) -> Computation:
145
150
  """
146
151
  Polls the given computation until it reaches the 'Completed' or 'Failed' state.
152
+
153
+ - `polling_interval` and `timeout` are in seconds
147
154
  """
155
+ if polling_interval < 5:
156
+ raise ValueError(
157
+ f"Polling interval {polling_interval} should be greater than or equal to 5"
158
+ )
159
+ if timeout is not None and timeout < polling_interval:
160
+ raise ValueError(
161
+ f"Timeout {timeout} should be greater than or equal to polling interval {polling_interval}"
162
+ )
163
+ if timeout is not None and timeout < 0:
164
+ raise ValueError(
165
+ f"Timeout {timeout} should be greater than or equal to 0 (seconds), or None"
166
+ )
167
+ t0 = time()
148
168
  while True:
149
169
  comp = self.get_computation(computation.id)
150
170
 
151
171
  if comp.state in [ComputationState.Completed, ComputationState.Failed]:
152
172
  return comp
153
173
 
154
- sleep(5)
174
+ if timeout is not None and (time() - t0) > timeout:
175
+ raise TimeoutError(f"Computation {computation.id} did not complete within {timeout} seconds")
176
+
177
+ sleep(polling_interval)
155
178
 
156
179
  def list_computation_results(self, computation_id: str, path: str = "") -> Folder:
157
180
  data = {
@@ -3,7 +3,7 @@ from __future__ import annotations
3
3
  from dataclasses_json import dataclass_json
4
4
  from dataclasses import dataclass
5
5
  from requests_toolbelt.sessions import BaseUrlSession
6
- from time import sleep
6
+ from time import sleep, time
7
7
  from typing import Optional
8
8
 
9
9
  from codeocean.components import SortOrder, SearchFilter, Permissions
@@ -237,17 +237,40 @@ class DataAssets:
237
237
 
238
238
  return DataAsset.from_dict(res.json())
239
239
 
240
- def wait_until_ready(self, data_asset: DataAsset) -> DataAsset:
240
+ def wait_until_ready(
241
+ self,
242
+ data_asset: DataAsset,
243
+ polling_interval: float = 5,
244
+ timeout: float | None = None,
245
+ ) -> DataAsset:
241
246
  """
242
247
  Polls the given data asset until it reaches the 'Ready' or 'Failed' state.
248
+
249
+ - `polling_interval` and `timeout` are in seconds
243
250
  """
251
+ if polling_interval < 5:
252
+ raise ValueError(
253
+ f"Polling interval {polling_interval} should be greater than or equal to 5"
254
+ )
255
+ if timeout is not None and timeout < polling_interval:
256
+ raise ValueError(
257
+ f"Timeout {timeout} should be greater than or equal to polling interval {polling_interval}"
258
+ )
259
+ if timeout is not None and timeout < 0:
260
+ raise ValueError(
261
+ f"Timeout {timeout} should be greater than or equal to 0 (seconds), or None"
262
+ )
263
+ t0 = time()
244
264
  while True:
245
265
  da = self.get_data_asset(data_asset.id)
246
266
 
247
267
  if da.state in [DataAssetState.Ready, DataAssetState.Failed]:
248
268
  return da
249
269
 
250
- sleep(5)
270
+ if timeout is not None and (time() - t0) > timeout:
271
+ raise TimeoutError(f"Data asset {data_asset.id} was not ready within {timeout} seconds")
272
+
273
+ sleep(polling_interval)
251
274
 
252
275
  def delete_data_asset(self, data_asset_id: str):
253
276
  self.client.delete(f"data_assets/{data_asset_id}")
File without changes
File without changes
File without changes
File without changes
File without changes