|
33 | 33 | from .http_util import http |
34 | 34 | from .s3utils import download_file, download_gz_file, upload_file |
35 | 35 | from .stub import TaskStub |
36 | | -from .task_info import BatchDetail |
| 36 | +from .task_info import BatchDetail, TaskInfo |
37 | 37 | from .types import PayType, Queryable, ResourceLifecycle, Submittable, Tidy3DResource |
38 | 38 |
|
39 | 39 |
|
@@ -204,6 +204,7 @@ def create( |
204 | 204 | "groupName": task_name, |
205 | 205 | "folderId": folder.folder_id, |
206 | 206 | "fileType": file_type, |
| 207 | + "taskType": task_type, |
207 | 208 | } |
208 | 209 | resp = http.post("rf/task", payload) |
209 | 210 | else: |
@@ -363,6 +364,33 @@ def is_batch(resource_id: str) -> bool: |
363 | 364 | except Exception: |
364 | 365 | return False |
365 | 366 |
|
| 367 | + def delete(self, versions: bool = False) -> None: |
| 368 | + """Delete current task from server. |
| 369 | +
|
| 370 | + Parameters |
| 371 | + ---------- |
| 372 | + versions : bool = False |
| 373 | + If ``True``, delete all versions of the task in the task group. Otherwise, delete only |
| 374 | + the version associated with the current task ID. |
| 375 | + """ |
| 376 | + if not self.task_id: |
| 377 | + raise ValueError("Task id not found.") |
| 378 | + |
| 379 | + task_details = self.detail() |
| 380 | + |
| 381 | + if task_details and "groupId" in task_details: |
| 382 | + group_id = task_details["groupId"] |
| 383 | + if versions: |
| 384 | + http.delete("tidy3d/group", json={"groupIds": [group_id]}) |
| 385 | + return |
| 386 | + elif "version" in task_details: |
| 387 | + version = task_details["version"] |
| 388 | + http.delete(f"tidy3d/group/{group_id}/versions", json={"versions": [version]}) |
| 389 | + return |
| 390 | + |
| 391 | + # Fallback to old method if we can't get the groupId and version |
| 392 | + http.delete(f"tidy3d/tasks/{self.task_id}") |
| 393 | + |
366 | 394 |
|
367 | 395 | class SimulationTask(WebTask): |
368 | 396 | """Interface for managing the running of solver tasks on the server.""" |
@@ -455,28 +483,16 @@ def get_running_tasks(cls) -> list[SimulationTask]: |
455 | 483 | return [] |
456 | 484 | return parse_obj_as(list[SimulationTask], resp) |
457 | 485 |
|
458 | | - def delete(self, versions: bool = False) -> None: |
459 | | - """Delete current task from server. |
| 486 | + def detail(self) -> TaskInfo: |
| 487 | + """Fetches the detailed information and status of the task. |
460 | 488 |
|
461 | | - Parameters |
462 | | - ---------- |
463 | | - versions : bool = False |
464 | | - If ``True``, delete all versions of the task in the task group. Otherwise, delete only the version associated with the current task ID. |
| 489 | + Returns |
| 490 | + ------- |
| 491 | + TaskInfo |
| 492 | + An object containing the task's latest data. |
465 | 493 | """ |
466 | | - if not self.task_id: |
467 | | - raise ValueError("Task id not found.") |
468 | | - |
469 | | - task_details = http.get(f"tidy3d/tasks/{self.task_id}") |
470 | | - |
471 | | - if task_details and "groupId" in task_details and "version" in task_details: |
472 | | - group_id = task_details["groupId"] |
473 | | - version = task_details["version"] |
474 | | - if versions: |
475 | | - http.delete("tidy3d/group", json={"groupIds": [group_id]}) |
476 | | - else: |
477 | | - http.delete(f"tidy3d/group/{group_id}/versions", json={"versions": [version]}) |
478 | | - else: # Fallback to old method if we can't get the groupId and version |
479 | | - http.delete(f"tidy3d/tasks/{self.task_id}") |
| 494 | + resp = http.get(f"tidy3d/tasks/{self.task_id}/detail") |
| 495 | + return TaskInfo(**{"taskId": self.task_id, "taskType": self.task_type, **resp}) |
480 | 496 |
|
481 | 497 | def get_simulation_json(self, to_file: PathLike, verbose: bool = True) -> None: |
482 | 498 | """Get json file for a :class:`.Simulation` from server. |
@@ -945,20 +961,6 @@ def abort(self) -> requests.Response: |
945 | 961 | raise ValueError("Batch id not found.") |
946 | 962 | return http.put(f"rf/task/{self.task_id}/abort", {}) |
947 | 963 |
|
948 | | - def delete(self, versions: bool = False) -> None: |
949 | | - """Delete current batch task from server. |
950 | | -
|
951 | | - Parameters |
952 | | - ---------- |
953 | | - versions : bool = False |
954 | | - Ignored for batch tasks; present for API compatibility. |
955 | | - """ |
956 | | - if not self.task_id: |
957 | | - raise ValueError("Batch id not found.") |
958 | | - if versions: |
959 | | - raise NotImplementedError("Deleting all versions is not supported for batch tasks.") |
960 | | - http.delete(f"rf/task/{self.task_id}") |
961 | | - |
962 | 964 |
|
963 | 965 | class TaskFactory: |
964 | 966 | """Factory for obtaining the correct task subclass.""" |
|
0 commit comments