Skip to content

Commit 7003526

Browse files
committed
Add initial support for Task
1 parent 825363c commit 7003526

17 files changed

+1443
-0
lines changed

infrahub_sdk/client.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
from .query_groups import InfrahubGroupContext, InfrahubGroupContextSync
5151
from .schema import InfrahubSchema, InfrahubSchemaSync, NodeSchemaAPI
5252
from .store import NodeStore, NodeStoreSync
53+
from .task.manager import InfrahubTaskManager, InfrahubTaskManagerSync
5354
from .timestamp import Timestamp
5455
from .types import AsyncRequester, HTTPMethod, Order, SyncRequester
5556
from .utils import decode_json, get_user_permissions, is_valid_uuid
@@ -268,6 +269,7 @@ def _initialize(self) -> None:
268269
self.branch = InfrahubBranchManager(self)
269270
self.object_store = ObjectStore(self)
270271
self.store = NodeStore()
272+
self.task = InfrahubTaskManager(self)
271273
self.concurrent_execution_limit = asyncio.Semaphore(self.max_concurrent_execution)
272274
self._request_method: AsyncRequester = self.config.requester or self._default_request_method
273275
self.group_context = InfrahubGroupContext(self)
@@ -1500,13 +1502,19 @@ async def __aexit__(
15001502

15011503

15021504
class InfrahubClientSync(BaseClient):
1505+
schema: InfrahubSchemaSync
1506+
branch: InfrahubBranchManagerSync
1507+
object_store: ObjectStoreSync
1508+
store: NodeStoreSync
1509+
task: InfrahubTaskManagerSync
15031510
group_context: InfrahubGroupContextSync
15041511

15051512
def _initialize(self) -> None:
15061513
self.schema = InfrahubSchemaSync(self)
15071514
self.branch = InfrahubBranchManagerSync(self)
15081515
self.object_store = ObjectStoreSync(self)
15091516
self.store = NodeStoreSync()
1517+
self.task = InfrahubTaskManagerSync(self)
15101518
self._request_method: SyncRequester = self.config.sync_requester or self._default_request_method
15111519
self.group_context = InfrahubGroupContextSync(self)
15121520

infrahub_sdk/task/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

infrahub_sdk/task/constants.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from .models import TaskState
2+
3+
FINAL_STATES = [TaskState.COMPLETED, TaskState.FAILED, TaskState.CANCELLED, TaskState.CRASHED]

infrahub_sdk/task/exceptions.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from __future__ import annotations
2+
3+
4+
class TaskError(Exception):
5+
def __init__(self, message: str | None = None):
6+
self.message = message
7+
super().__init__(self.message)
8+
9+
10+
class TaskNotFoundError(TaskError):
11+
def __init__(self, id: str):
12+
self.message = f"Task with id {id} not found"
13+
super().__init__(self.message)
14+
15+
16+
class TooManyTasksError(TaskError):
17+
def __init__(self, expected_id: str, received_ids: list[str]):
18+
self.message = f"Expected 1 task with id {expected_id}, but got {len(received_ids)}"
19+
super().__init__(self.message)
20+
21+
22+
class TaskNotCompletedError(TaskError):
23+
def __init__(self, id: str, message: str | None = None):
24+
self.message = message or f"Task with id {id} is not completed"
25+
super().__init__(self.message)

0 commit comments

Comments
 (0)