orca-sdk 0.1.2__py3-none-any.whl → 0.1.4__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.
orca_sdk/job.py CHANGED
@@ -7,7 +7,7 @@ from typing import Callable, Generic, TypedDict, TypeVar, cast
7
7
 
8
8
  from tqdm.auto import tqdm
9
9
 
10
- from .client import orca_api
10
+ from .client import OrcaClient
11
11
 
12
12
 
13
13
  class JobConfig(TypedDict):
@@ -17,7 +17,7 @@ class JobConfig(TypedDict):
17
17
 
18
18
 
19
19
  class Status(Enum):
20
- """Status of a cloud job in the task queue"""
20
+ """Status of a cloud job in the job queue"""
21
21
 
22
22
  # the INITIALIZED state should never be returned by the API
23
23
  INITIALIZED = "INITIALIZED"
@@ -140,8 +140,9 @@ class Job(Generic[TResult]):
140
140
  Returns:
141
141
  List of jobs matching the given filters
142
142
  """
143
- paginated_tasks = orca_api.GET(
144
- "/task",
143
+ client = OrcaClient._resolve_client()
144
+ paginated_jobs = client.GET(
145
+ "/job",
145
146
  params={
146
147
  "status": (
147
148
  [s.value for s in status]
@@ -174,7 +175,7 @@ class Job(Generic[TResult]):
174
175
  obj,
175
176
  )[-1]
176
177
  )(t)
177
- for t in paginated_tasks["items"]
178
+ for t in paginated_jobs["items"]
178
179
  ]
179
180
 
180
181
  def __init__(self, id: str, get_value: Callable[[], TResult | None] | None = None):
@@ -186,27 +187,30 @@ class Job(Generic[TResult]):
186
187
  get_value: Optional function to customize how the value is resolved, if not provided the result will be a dict
187
188
  """
188
189
  self.id = id
189
- task = orca_api.GET("/task/{task_id}", params={"task_id": id})
190
-
191
- self._get_value = get_value or (
192
- lambda: cast(TResult | None, orca_api.GET("/task/{task_id}", params={"task_id": id})["result"])
193
- )
194
- self.type = task["type"]
195
- self.status = Status(task["status"])
196
- self.steps_total = task["steps_total"]
197
- self.steps_completed = task["steps_completed"]
198
- self.exception = task["exception"]
190
+ client = OrcaClient._resolve_client()
191
+ job = client.GET("/job/{job_id}", params={"job_id": id})
192
+
193
+ def default_get_value():
194
+ client = OrcaClient._resolve_client()
195
+ return cast(TResult | None, client.GET("/job/{job_id}", params={"job_id": id})["result"])
196
+
197
+ self._get_value = get_value or default_get_value
198
+ self.type = job["type"]
199
+ self.status = Status(job["status"])
200
+ self.steps_total = job["steps_total"]
201
+ self.steps_completed = job["steps_completed"]
202
+ self.exception = job["exception"]
199
203
  self.value = (
200
204
  None
201
- if task["status"] != "COMPLETED"
205
+ if job["status"] != "COMPLETED"
202
206
  else (
203
207
  get_value()
204
208
  if get_value is not None
205
- else cast(TResult, task["result"]) if task["result"] is not None else None
209
+ else cast(TResult, job["result"]) if job["result"] is not None else None
206
210
  )
207
211
  )
208
- self.updated_at = datetime.fromisoformat(task["updated_at"])
209
- self.created_at = datetime.fromisoformat(task["created_at"])
212
+ self.updated_at = datetime.fromisoformat(job["updated_at"])
213
+ self.created_at = datetime.fromisoformat(job["created_at"])
210
214
  self.refreshed_at = datetime.now()
211
215
 
212
216
  def refresh(self, throttle: float = 0):
@@ -222,7 +226,8 @@ class Job(Generic[TResult]):
222
226
  return
223
227
  self.refreshed_at = current_time
224
228
 
225
- status_info = orca_api.GET("/task/{task_id}/status", params={"task_id": self.id})
229
+ client = OrcaClient._resolve_client()
230
+ status_info = client.GET("/job/{job_id}/status", params={"job_id": self.id})
226
231
  self.status = Status(status_info["status"])
227
232
  if status_info["steps_total"] is not None:
228
233
  self.steps_total = status_info["steps_total"]
@@ -333,5 +338,6 @@ def abort(self, show_progress: bool = False, refresh_interval: int = 1, max_wait
333
338
  refresh_interval: Polling interval in seconds while waiting for the job to abort
334
339
  max_wait: Maximum time to wait for the job to abort in seconds
335
340
  """
336
- orca_api.DELETE("/task/{task_id}/abort", params={"task_id": self.id})
341
+ client = OrcaClient._resolve_client()
342
+ client.DELETE("/job/{job_id}/abort", params={"job_id": self.id})
337
343
  self.wait(show_progress, refresh_interval, max_wait)