hatchet-sdk 1.0.0a1__py3-none-any.whl → 1.0.2__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.

Potentially problematic release.


This version of hatchet-sdk might be problematic. Click here for more details.

Files changed (32) hide show
  1. hatchet_sdk/__init__.py +5 -0
  2. hatchet_sdk/client.py +17 -5
  3. hatchet_sdk/clients/admin.py +1 -18
  4. hatchet_sdk/clients/dispatcher/action_listener.py +2 -4
  5. hatchet_sdk/clients/durable_event_listener.py +6 -3
  6. hatchet_sdk/clients/events.py +1 -2
  7. hatchet_sdk/clients/rest/models/workflow_runs_metrics.py +5 -1
  8. hatchet_sdk/clients/v1/api_client.py +81 -0
  9. hatchet_sdk/clients/workflow_listener.py +6 -3
  10. hatchet_sdk/context/context.py +1 -12
  11. hatchet_sdk/features/cron.py +89 -119
  12. hatchet_sdk/features/logs.py +16 -0
  13. hatchet_sdk/features/metrics.py +75 -0
  14. hatchet_sdk/features/rate_limits.py +45 -0
  15. hatchet_sdk/features/runs.py +221 -0
  16. hatchet_sdk/features/scheduled.py +114 -131
  17. hatchet_sdk/features/workers.py +41 -0
  18. hatchet_sdk/features/workflows.py +55 -0
  19. hatchet_sdk/hatchet.py +36 -14
  20. hatchet_sdk/runnables/standalone.py +9 -11
  21. hatchet_sdk/runnables/types.py +1 -1
  22. hatchet_sdk/runnables/workflow.py +26 -19
  23. hatchet_sdk/worker/action_listener_process.py +3 -3
  24. hatchet_sdk/worker/runner/run_loop_manager.py +0 -1
  25. hatchet_sdk/worker/runner/runner.py +4 -11
  26. hatchet_sdk/worker/runner/utils/capture_logs.py +0 -3
  27. hatchet_sdk/worker/worker.py +30 -21
  28. {hatchet_sdk-1.0.0a1.dist-info → hatchet_sdk-1.0.2.dist-info}/METADATA +2 -1
  29. {hatchet_sdk-1.0.0a1.dist-info → hatchet_sdk-1.0.2.dist-info}/RECORD +31 -25
  30. hatchet_sdk/clients/rest_client.py +0 -657
  31. {hatchet_sdk-1.0.0a1.dist-info → hatchet_sdk-1.0.2.dist-info}/WHEEL +0 -0
  32. {hatchet_sdk-1.0.0a1.dist-info → hatchet_sdk-1.0.2.dist-info}/entry_points.txt +0 -0
@@ -0,0 +1,75 @@
1
+ from hatchet_sdk.clients.rest.api.tenant_api import TenantApi
2
+ from hatchet_sdk.clients.rest.api.workflow_api import WorkflowApi
3
+ from hatchet_sdk.clients.rest.api_client import ApiClient
4
+ from hatchet_sdk.clients.rest.models.tenant_queue_metrics import TenantQueueMetrics
5
+ from hatchet_sdk.clients.rest.models.tenant_step_run_queue_metrics import (
6
+ TenantStepRunQueueMetrics,
7
+ )
8
+ from hatchet_sdk.clients.rest.models.workflow_metrics import WorkflowMetrics
9
+ from hatchet_sdk.clients.rest.models.workflow_run_status import WorkflowRunStatus
10
+ from hatchet_sdk.clients.v1.api_client import (
11
+ BaseRestClient,
12
+ maybe_additional_metadata_to_kv,
13
+ )
14
+ from hatchet_sdk.utils.typing import JSONSerializableMapping
15
+
16
+
17
+ class MetricsClient(BaseRestClient):
18
+ def _wa(self, client: ApiClient) -> WorkflowApi:
19
+ return WorkflowApi(client)
20
+
21
+ def _ta(self, client: ApiClient) -> TenantApi:
22
+ return TenantApi(client)
23
+
24
+ async def aio_get_workflow_metrics(
25
+ self,
26
+ workflow_id: str,
27
+ status: WorkflowRunStatus | None = None,
28
+ group_key: str | None = None,
29
+ ) -> WorkflowMetrics:
30
+ async with self.client() as client:
31
+ return await self._wa(client).workflow_get_metrics(
32
+ workflow=workflow_id, status=status, group_key=group_key
33
+ )
34
+
35
+ def get_workflow_metrics(
36
+ self,
37
+ workflow_id: str,
38
+ status: WorkflowRunStatus | None = None,
39
+ group_key: str | None = None,
40
+ ) -> WorkflowMetrics:
41
+ return self._run_async_from_sync(
42
+ self.aio_get_workflow_metrics, workflow_id, status, group_key
43
+ )
44
+
45
+ async def aio_get_queue_metrics(
46
+ self,
47
+ workflow_ids: list[str] | None = None,
48
+ additional_metadata: JSONSerializableMapping | None = None,
49
+ ) -> TenantQueueMetrics:
50
+ async with self.client() as client:
51
+ return await self._wa(client).tenant_get_queue_metrics(
52
+ tenant=self.client_config.tenant_id,
53
+ workflows=workflow_ids,
54
+ additional_metadata=maybe_additional_metadata_to_kv(
55
+ additional_metadata
56
+ ),
57
+ )
58
+
59
+ def get_queue_metrics(
60
+ self,
61
+ workflow_ids: list[str] | None = None,
62
+ additional_metadata: JSONSerializableMapping | None = None,
63
+ ) -> TenantQueueMetrics:
64
+ return self._run_async_from_sync(
65
+ self.aio_get_queue_metrics, workflow_ids, additional_metadata
66
+ )
67
+
68
+ async def aio_get_task_metrics(self) -> TenantStepRunQueueMetrics:
69
+ async with self.client() as client:
70
+ return await self._ta(client).tenant_get_step_run_queue_metrics(
71
+ tenant=self.client_config.tenant_id
72
+ )
73
+
74
+ def get_task_metrics(self) -> TenantStepRunQueueMetrics:
75
+ return self._run_async_from_sync(self.aio_get_task_metrics)
@@ -0,0 +1,45 @@
1
+ import asyncio
2
+
3
+ from hatchet_sdk.clients.rest.tenacity_utils import tenacity_retry
4
+ from hatchet_sdk.clients.v1.api_client import BaseRestClient
5
+ from hatchet_sdk.connection import new_conn
6
+ from hatchet_sdk.contracts import workflows_pb2 as v0_workflow_protos
7
+ from hatchet_sdk.contracts.v1 import workflows_pb2 as workflow_protos
8
+ from hatchet_sdk.contracts.workflows_pb2_grpc import WorkflowServiceStub
9
+ from hatchet_sdk.metadata import get_metadata
10
+ from hatchet_sdk.rate_limit import RateLimitDuration
11
+ from hatchet_sdk.utils.proto_enums import convert_python_enum_to_proto
12
+
13
+
14
+ class RateLimitsClient(BaseRestClient):
15
+ @tenacity_retry
16
+ def put(
17
+ self,
18
+ key: str,
19
+ limit: int,
20
+ duration: RateLimitDuration = RateLimitDuration.SECOND,
21
+ ) -> None:
22
+ duration_proto = convert_python_enum_to_proto(
23
+ duration, workflow_protos.RateLimitDuration
24
+ )
25
+
26
+ conn = new_conn(self.client_config, False)
27
+ client = WorkflowServiceStub(conn) # type: ignore[no-untyped-call]
28
+
29
+ client.PutRateLimit(
30
+ v0_workflow_protos.PutRateLimitRequest(
31
+ key=key,
32
+ limit=limit,
33
+ duration=duration_proto, # type: ignore[arg-type]
34
+ ),
35
+ metadata=get_metadata(self.client_config.token),
36
+ )
37
+
38
+ @tenacity_retry
39
+ async def aio_put(
40
+ self,
41
+ key: str,
42
+ limit: int,
43
+ duration: RateLimitDuration = RateLimitDuration.SECOND,
44
+ ) -> None:
45
+ await asyncio.to_thread(self.put, key, limit, duration)
@@ -0,0 +1,221 @@
1
+ from datetime import datetime, timedelta
2
+ from typing import Literal, overload
3
+
4
+ from pydantic import BaseModel, model_validator
5
+
6
+ from hatchet_sdk.clients.rest.api.task_api import TaskApi
7
+ from hatchet_sdk.clients.rest.api.workflow_runs_api import WorkflowRunsApi
8
+ from hatchet_sdk.clients.rest.api_client import ApiClient
9
+ from hatchet_sdk.clients.rest.models.v1_cancel_task_request import V1CancelTaskRequest
10
+ from hatchet_sdk.clients.rest.models.v1_replay_task_request import V1ReplayTaskRequest
11
+ from hatchet_sdk.clients.rest.models.v1_task_filter import V1TaskFilter
12
+ from hatchet_sdk.clients.rest.models.v1_task_status import V1TaskStatus
13
+ from hatchet_sdk.clients.rest.models.v1_task_summary_list import V1TaskSummaryList
14
+ from hatchet_sdk.clients.rest.models.v1_trigger_workflow_run_request import (
15
+ V1TriggerWorkflowRunRequest,
16
+ )
17
+ from hatchet_sdk.clients.rest.models.v1_workflow_run_details import V1WorkflowRunDetails
18
+ from hatchet_sdk.clients.v1.api_client import (
19
+ BaseRestClient,
20
+ maybe_additional_metadata_to_kv,
21
+ )
22
+ from hatchet_sdk.utils.typing import JSONSerializableMapping
23
+
24
+
25
+ class RunFilter(BaseModel):
26
+ since: datetime
27
+ until: datetime | None = None
28
+ statuses: list[V1TaskStatus] | None = None
29
+ workflow_ids: list[str] | None = None
30
+ additional_metadata: dict[str, str] | None = None
31
+
32
+
33
+ class BulkCancelReplayOpts(BaseModel):
34
+ ids: list[str] | None = None
35
+ filters: RunFilter | None = None
36
+
37
+ @model_validator(mode="after")
38
+ def validate_model(self) -> "BulkCancelReplayOpts":
39
+ if not self.ids and not self.filters:
40
+ raise ValueError("ids or filters must be set")
41
+
42
+ if self.ids and self.filters:
43
+ raise ValueError("ids and filters cannot both be set")
44
+
45
+ return self
46
+
47
+ @property
48
+ def v1_task_filter(self) -> V1TaskFilter | None:
49
+ if not self.filters:
50
+ return None
51
+
52
+ return V1TaskFilter(
53
+ since=self.filters.since,
54
+ until=self.filters.until,
55
+ statuses=self.filters.statuses,
56
+ workflowIds=self.filters.workflow_ids,
57
+ additionalMetadata=maybe_additional_metadata_to_kv(
58
+ self.filters.additional_metadata
59
+ ),
60
+ )
61
+
62
+ @overload
63
+ def to_request(self, request_type: Literal["replay"]) -> V1ReplayTaskRequest: ...
64
+
65
+ @overload
66
+ def to_request(self, request_type: Literal["cancel"]) -> V1CancelTaskRequest: ...
67
+
68
+ def to_request(
69
+ self, request_type: Literal["replay", "cancel"]
70
+ ) -> V1ReplayTaskRequest | V1CancelTaskRequest:
71
+ if request_type == "replay":
72
+ return V1ReplayTaskRequest(
73
+ externalIds=self.ids,
74
+ filter=self.v1_task_filter,
75
+ )
76
+
77
+ if request_type == "cancel":
78
+ return V1CancelTaskRequest(
79
+ externalIds=self.ids,
80
+ filter=self.v1_task_filter,
81
+ )
82
+
83
+
84
+ class RunsClient(BaseRestClient):
85
+ def _wra(self, client: ApiClient) -> WorkflowRunsApi:
86
+ return WorkflowRunsApi(client)
87
+
88
+ def _ta(self, client: ApiClient) -> TaskApi:
89
+ return TaskApi(client)
90
+
91
+ async def aio_get(self, workflow_run_id: str) -> V1WorkflowRunDetails:
92
+ async with self.client() as client:
93
+ return await self._wra(client).v1_workflow_run_get(str(workflow_run_id))
94
+
95
+ def get(self, workflow_run_id: str) -> V1WorkflowRunDetails:
96
+ return self._run_async_from_sync(self.aio_get, workflow_run_id)
97
+
98
+ async def aio_list(
99
+ self,
100
+ since: datetime = datetime.now() - timedelta(hours=1),
101
+ only_tasks: bool = False,
102
+ offset: int | None = None,
103
+ limit: int | None = None,
104
+ statuses: list[V1TaskStatus] | None = None,
105
+ until: datetime | None = None,
106
+ additional_metadata: dict[str, str] | None = None,
107
+ workflow_ids: list[str] | None = None,
108
+ worker_id: str | None = None,
109
+ parent_task_external_id: str | None = None,
110
+ ) -> V1TaskSummaryList:
111
+ async with self.client() as client:
112
+ return await self._wra(client).v1_workflow_run_list(
113
+ tenant=self.client_config.tenant_id,
114
+ since=since,
115
+ only_tasks=only_tasks,
116
+ offset=offset,
117
+ limit=limit,
118
+ statuses=statuses,
119
+ until=until,
120
+ additional_metadata=maybe_additional_metadata_to_kv(
121
+ additional_metadata
122
+ ),
123
+ workflow_ids=workflow_ids,
124
+ worker_id=worker_id,
125
+ parent_task_external_id=parent_task_external_id,
126
+ )
127
+
128
+ def list(
129
+ self,
130
+ since: datetime = datetime.now() - timedelta(hours=1),
131
+ only_tasks: bool = False,
132
+ offset: int | None = None,
133
+ limit: int | None = None,
134
+ statuses: list[V1TaskStatus] | None = None,
135
+ until: datetime | None = None,
136
+ additional_metadata: dict[str, str] | None = None,
137
+ workflow_ids: list[str] | None = None,
138
+ worker_id: str | None = None,
139
+ parent_task_external_id: str | None = None,
140
+ ) -> V1TaskSummaryList:
141
+ return self._run_async_from_sync(
142
+ self.aio_list,
143
+ since=since,
144
+ only_tasks=only_tasks,
145
+ offset=offset,
146
+ limit=limit,
147
+ statuses=statuses,
148
+ until=until,
149
+ additional_metadata=additional_metadata,
150
+ workflow_ids=workflow_ids,
151
+ worker_id=worker_id,
152
+ parent_task_external_id=parent_task_external_id,
153
+ )
154
+
155
+ async def aio_create(
156
+ self,
157
+ workflow_name: str,
158
+ input: JSONSerializableMapping,
159
+ additional_metadata: JSONSerializableMapping = {},
160
+ ) -> V1WorkflowRunDetails:
161
+ async with self.client() as client:
162
+ return await self._wra(client).v1_workflow_run_create(
163
+ tenant=self.client_config.tenant_id,
164
+ v1_trigger_workflow_run_request=V1TriggerWorkflowRunRequest(
165
+ workflowName=workflow_name,
166
+ input=dict(input),
167
+ additionalMetadata=dict(additional_metadata),
168
+ ),
169
+ )
170
+
171
+ def create(
172
+ self,
173
+ workflow_name: str,
174
+ input: JSONSerializableMapping,
175
+ additional_metadata: JSONSerializableMapping = {},
176
+ ) -> V1WorkflowRunDetails:
177
+ return self._run_async_from_sync(
178
+ self.aio_create, workflow_name, input, additional_metadata
179
+ )
180
+
181
+ async def aio_replay(self, run_id: str) -> None:
182
+ await self.aio_bulk_replay(opts=BulkCancelReplayOpts(ids=[run_id]))
183
+
184
+ def replay(self, run_id: str) -> None:
185
+ return self._run_async_from_sync(self.aio_replay, run_id)
186
+
187
+ async def aio_bulk_replay(self, opts: BulkCancelReplayOpts) -> None:
188
+ async with self.client() as client:
189
+ await self._ta(client).v1_task_replay(
190
+ tenant=self.client_config.tenant_id,
191
+ v1_replay_task_request=opts.to_request("replay"),
192
+ )
193
+
194
+ def bulk_replay(self, opts: BulkCancelReplayOpts) -> None:
195
+ return self._run_async_from_sync(self.aio_bulk_replay, opts)
196
+
197
+ async def aio_cancel(self, run_id: str) -> None:
198
+ await self.aio_bulk_cancel(opts=BulkCancelReplayOpts(ids=[run_id]))
199
+
200
+ def cancel(self, run_id: str) -> None:
201
+ return self._run_async_from_sync(self.aio_cancel, run_id)
202
+
203
+ async def aio_bulk_cancel(self, opts: BulkCancelReplayOpts) -> None:
204
+ async with self.client() as client:
205
+ await self._ta(client).v1_task_cancel(
206
+ tenant=self.client_config.tenant_id,
207
+ v1_cancel_task_request=opts.to_request("cancel"),
208
+ )
209
+
210
+ def bulk_cancel(self, opts: BulkCancelReplayOpts) -> None:
211
+ return self._run_async_from_sync(self.aio_bulk_cancel, opts)
212
+
213
+ async def aio_get_result(self, run_id: str) -> JSONSerializableMapping:
214
+ details = await self.aio_get(run_id)
215
+
216
+ return details.run.output
217
+
218
+ def get_result(self, run_id: str) -> JSONSerializableMapping:
219
+ details = self.get(run_id)
220
+
221
+ return details.run.output
@@ -1,12 +1,13 @@
1
1
  import datetime
2
- from typing import List, Optional, Union
2
+ from typing import Optional
3
3
 
4
- from pydantic import BaseModel, Field
5
-
6
- from hatchet_sdk.client import Client
7
- from hatchet_sdk.clients.rest.models.cron_workflows_order_by_field import (
8
- CronWorkflowsOrderByField,
4
+ from hatchet_sdk.clients.rest.api.workflow_api import WorkflowApi
5
+ from hatchet_sdk.clients.rest.api.workflow_run_api import WorkflowRunApi
6
+ from hatchet_sdk.clients.rest.api_client import ApiClient
7
+ from hatchet_sdk.clients.rest.models.schedule_workflow_run_request import (
8
+ ScheduleWorkflowRunRequest,
9
9
  )
10
+ from hatchet_sdk.clients.rest.models.scheduled_run_status import ScheduledRunStatus
10
11
  from hatchet_sdk.clients.rest.models.scheduled_workflows import ScheduledWorkflows
11
12
  from hatchet_sdk.clients.rest.models.scheduled_workflows_list import (
12
13
  ScheduledWorkflowsList,
@@ -17,43 +18,49 @@ from hatchet_sdk.clients.rest.models.scheduled_workflows_order_by_field import (
17
18
  from hatchet_sdk.clients.rest.models.workflow_run_order_by_direction import (
18
19
  WorkflowRunOrderByDirection,
19
20
  )
21
+ from hatchet_sdk.clients.v1.api_client import (
22
+ BaseRestClient,
23
+ maybe_additional_metadata_to_kv,
24
+ )
20
25
  from hatchet_sdk.utils.typing import JSONSerializableMapping
21
26
 
22
27
 
23
- class CreateScheduledTriggerConfig(BaseModel):
24
- """
25
- Schema for creating a scheduled workflow run.
26
-
27
- Attributes:
28
- input (JSONSerializableMapping): The input data for the scheduled workflow.
29
- additional_metadata (JSONSerializableMapping): Additional metadata associated with the future run (e.g. ["key1:value1", "key2:value2"]).
30
- trigger_at (Optional[datetime.datetime]): The datetime when the run should be triggered.
31
- """
32
-
33
- input: JSONSerializableMapping = Field(default_factory=dict)
34
- additional_metadata: JSONSerializableMapping = Field(default_factory=dict)
35
- trigger_at: datetime.datetime
36
-
37
-
38
- class ScheduledClient:
39
- """
40
- Client for managing scheduled workflows synchronously.
28
+ class ScheduledClient(BaseRestClient):
29
+ def _wra(self, client: ApiClient) -> WorkflowRunApi:
30
+ return WorkflowRunApi(client)
41
31
 
42
- Attributes:
43
- _client (Client): The underlying client used to interact with the REST API.
44
- aio (ScheduledClientAsync): Asynchronous counterpart of ScheduledClient.
45
- """
32
+ def _wa(self, client: ApiClient) -> WorkflowApi:
33
+ return WorkflowApi(client)
46
34
 
47
- _client: Client
48
-
49
- def __init__(self, _client: Client) -> None:
35
+ async def aio_create(
36
+ self,
37
+ workflow_name: str,
38
+ trigger_at: datetime.datetime,
39
+ input: JSONSerializableMapping,
40
+ additional_metadata: JSONSerializableMapping,
41
+ ) -> ScheduledWorkflows:
50
42
  """
51
- Initializes the ScheduledClient with a given Client instance.
43
+ Creates a new scheduled workflow run asynchronously.
52
44
 
53
45
  Args:
54
- _client (Client): The client instance to be used for REST interactions.
46
+ workflow_name (str): The name of the scheduled workflow.
47
+ trigger_at (datetime.datetime): The datetime when the run should be triggered.
48
+ input (JSONSerializableMapping): The input data for the scheduled workflow.
49
+ additional_metadata (JSONSerializableMapping): Additional metadata associated with the future run.
50
+
51
+ Returns:
52
+ ScheduledWorkflows: The created scheduled workflow instance.
55
53
  """
56
- self._client = _client
54
+ async with self.client() as client:
55
+ return await self._wra(client).scheduled_workflow_run_create(
56
+ tenant=self.client_config.tenant_id,
57
+ workflow=workflow_name,
58
+ schedule_workflow_run_request=ScheduleWorkflowRunRequest(
59
+ triggerAt=trigger_at,
60
+ input=dict(input),
61
+ additionalMetadata=dict(additional_metadata),
62
+ ),
63
+ )
57
64
 
58
65
  def create(
59
66
  self,
@@ -75,37 +82,39 @@ class ScheduledClient:
75
82
  ScheduledWorkflows: The created scheduled workflow instance.
76
83
  """
77
84
 
78
- validated_input = CreateScheduledTriggerConfig(
79
- trigger_at=trigger_at, input=input, additional_metadata=additional_metadata
80
- )
81
-
82
- return self._client.rest.schedule_create(
85
+ return self._run_async_from_sync(
86
+ self.aio_create,
83
87
  workflow_name,
84
- validated_input.trigger_at,
85
- validated_input.input,
86
- validated_input.additional_metadata,
88
+ trigger_at,
89
+ input,
90
+ additional_metadata,
87
91
  )
88
92
 
89
- def delete(self, scheduled: Union[str, ScheduledWorkflows]) -> None:
93
+ async def aio_delete(self, scheduled_id: str) -> None:
90
94
  """
91
95
  Deletes a scheduled workflow run.
92
96
 
93
97
  Args:
94
- scheduled (Union[str, ScheduledWorkflows]): The scheduled workflow trigger ID or ScheduledWorkflows instance to delete.
98
+ scheduled_id (str): The scheduled workflow trigger ID to delete.
95
99
  """
96
- self._client.rest.schedule_delete(
97
- scheduled.metadata.id
98
- if isinstance(scheduled, ScheduledWorkflows)
99
- else scheduled
100
- )
100
+ async with self.client() as client:
101
+ await self._wa(client).workflow_scheduled_delete(
102
+ tenant=self.client_config.tenant_id,
103
+ scheduled_workflow_run=scheduled_id,
104
+ )
101
105
 
102
- def list(
106
+ def delete(self, scheduled_id: str) -> None:
107
+ self._run_async_from_sync(self.aio_delete, scheduled_id)
108
+
109
+ async def aio_list(
103
110
  self,
104
111
  offset: int | None = None,
105
112
  limit: int | None = None,
106
113
  workflow_id: str | None = None,
107
- additional_metadata: Optional[List[str]] = None,
108
- order_by_field: Optional[CronWorkflowsOrderByField] = None,
114
+ parent_workflow_run_id: str | None = None,
115
+ statuses: list[ScheduledRunStatus] | None = None,
116
+ additional_metadata: Optional[JSONSerializableMapping] = None,
117
+ order_by_field: Optional[ScheduledWorkflowsOrderByField] = None,
109
118
  order_by_direction: Optional[WorkflowRunOrderByDirection] = None,
110
119
  ) -> ScheduledWorkflowsList:
111
120
  """
@@ -115,120 +124,94 @@ class ScheduledClient:
115
124
  offset (int | None): The starting point for the list.
116
125
  limit (int | None): The maximum number of items to return.
117
126
  workflow_id (str | None): Filter by specific workflow ID.
118
- additional_metadata (Optional[List[str]]): Filter by additional metadata keys (e.g. ["key1:value1", "key2:value2"]).
119
- order_by_field (Optional[CronWorkflowsOrderByField]): Field to order the results by.
127
+ parent_workflow_run_id (str | None): Filter by parent workflow run ID.
128
+ statuses (list[ScheduledRunStatus] | None): Filter by status.
129
+ additional_metadata (Optional[List[dict[str, str]]]): Filter by additional metadata.
130
+ order_by_field (Optional[ScheduledWorkflowsOrderByField]): Field to order the results by.
120
131
  order_by_direction (Optional[WorkflowRunOrderByDirection]): Direction to order the results.
121
132
 
122
133
  Returns:
123
134
  List[ScheduledWorkflows]: A list of scheduled workflows matching the criteria.
124
135
  """
125
- return self._client.rest.schedule_list(
126
- offset=offset,
127
- limit=limit,
128
- workflow_id=workflow_id,
129
- additional_metadata=additional_metadata,
130
- order_by_field=order_by_field,
131
- order_by_direction=order_by_direction,
132
- )
133
-
134
- def get(self, scheduled: Union[str, ScheduledWorkflows]) -> ScheduledWorkflows:
135
- """
136
- Retrieves a specific scheduled workflow by scheduled run trigger ID.
137
-
138
- Args:
139
- scheduled (Union[str, ScheduledWorkflows]): The scheduled workflow trigger ID or ScheduledWorkflows instance to retrieve.
140
-
141
- Returns:
142
- ScheduledWorkflows: The requested scheduled workflow instance.
143
- """
144
- return self._client.rest.schedule_get(
145
- scheduled.metadata.id
146
- if isinstance(scheduled, ScheduledWorkflows)
147
- else scheduled
148
- )
149
-
150
- async def aio_create(
151
- self,
152
- workflow_name: str,
153
- trigger_at: datetime.datetime,
154
- input: JSONSerializableMapping,
155
- additional_metadata: JSONSerializableMapping,
156
- ) -> ScheduledWorkflows:
157
- """
158
- Creates a new scheduled workflow run asynchronously.
136
+ async with self.client() as client:
137
+ return await self._wa(client).workflow_scheduled_list(
138
+ tenant=self.client_config.tenant_id,
139
+ offset=offset,
140
+ limit=limit,
141
+ order_by_field=order_by_field,
142
+ order_by_direction=order_by_direction,
143
+ workflow_id=workflow_id,
144
+ additional_metadata=maybe_additional_metadata_to_kv(
145
+ additional_metadata
146
+ ),
147
+ parent_workflow_run_id=parent_workflow_run_id,
148
+ statuses=statuses,
149
+ )
159
150
 
160
- Args:
161
- workflow_name (str): The name of the scheduled workflow.
162
- trigger_at (datetime.datetime): The datetime when the run should be triggered.
163
- input (JSONSerializableMapping): The input data for the scheduled workflow.
164
- additional_metadata (JSONSerializableMapping): Additional metadata associated with the future run.
165
-
166
- Returns:
167
- ScheduledWorkflows: The created scheduled workflow instance.
168
- """
169
- return await self._client.rest.aio_create_schedule(
170
- workflow_name, trigger_at, input, additional_metadata
171
- )
172
-
173
- async def aio_delete(self, scheduled: Union[str, ScheduledWorkflows]) -> None:
174
- """
175
- Deletes a scheduled workflow asynchronously.
176
-
177
- Args:
178
- scheduled (Union[str, ScheduledWorkflows]): The scheduled workflow trigger ID or ScheduledWorkflows instance to delete.
179
- """
180
- await self._client.rest.aio_delete_schedule(
181
- scheduled.metadata.id
182
- if isinstance(scheduled, ScheduledWorkflows)
183
- else scheduled
184
- )
185
-
186
- async def aio_list(
151
+ def list(
187
152
  self,
188
153
  offset: int | None = None,
189
154
  limit: int | None = None,
190
155
  workflow_id: str | None = None,
191
- additional_metadata: Optional[List[str]] = None,
156
+ parent_workflow_run_id: str | None = None,
157
+ statuses: list[ScheduledRunStatus] | None = None,
158
+ additional_metadata: Optional[JSONSerializableMapping] = None,
192
159
  order_by_field: Optional[ScheduledWorkflowsOrderByField] = None,
193
160
  order_by_direction: Optional[WorkflowRunOrderByDirection] = None,
194
161
  ) -> ScheduledWorkflowsList:
195
162
  """
196
- Retrieves a list of scheduled workflows based on provided filters asynchronously.
163
+ Retrieves a list of scheduled workflows based on provided filters.
197
164
 
198
165
  Args:
199
166
  offset (int | None): The starting point for the list.
200
167
  limit (int | None): The maximum number of items to return.
201
168
  workflow_id (str | None): Filter by specific workflow ID.
202
- additional_metadata (Optional[List[str]]): Filter by additional metadata keys (e.g. ["key1:value1", "key2:value2"]).
203
- order_by_field (Optional[CronWorkflowsOrderByField]): Field to order the results by.
169
+ parent_workflow_run_id (str | None): Filter by parent workflow run ID.
170
+ statuses (list[ScheduledRunStatus] | None): Filter by status.
171
+ additional_metadata (Optional[List[dict[str, str]]]): Filter by additional metadata.
172
+ order_by_field (Optional[ScheduledWorkflowsOrderByField]): Field to order the results by.
204
173
  order_by_direction (Optional[WorkflowRunOrderByDirection]): Direction to order the results.
205
174
 
206
175
  Returns:
207
- ScheduledWorkflowsList: A list of scheduled workflows matching the criteria.
176
+ List[ScheduledWorkflows]: A list of scheduled workflows matching the criteria.
208
177
  """
209
- return await self._client.rest.aio_list_schedule(
178
+ return self._run_async_from_sync(
179
+ self.aio_list,
210
180
  offset=offset,
211
181
  limit=limit,
212
182
  workflow_id=workflow_id,
213
183
  additional_metadata=additional_metadata,
214
184
  order_by_field=order_by_field,
215
185
  order_by_direction=order_by_direction,
186
+ parent_workflow_run_id=parent_workflow_run_id,
187
+ statuses=statuses,
216
188
  )
217
189
 
218
- async def aio_get(
219
- self, scheduled: Union[str, ScheduledWorkflows]
220
- ) -> ScheduledWorkflows:
190
+ async def aio_get(self, scheduled_id: str) -> ScheduledWorkflows:
191
+ """
192
+ Retrieves a specific scheduled workflow by scheduled run trigger ID.
193
+
194
+ Args:
195
+ scheduled (str): The scheduled workflow trigger ID to retrieve.
196
+
197
+ Returns:
198
+ ScheduledWorkflows: The requested scheduled workflow instance.
221
199
  """
222
- Retrieves a specific scheduled workflow by scheduled run trigger ID asynchronously.
200
+
201
+ async with self.client() as client:
202
+ return await self._wa(client).workflow_scheduled_get(
203
+ tenant=self.client_config.tenant_id,
204
+ scheduled_workflow_run=scheduled_id,
205
+ )
206
+
207
+ def get(self, scheduled_id: str) -> ScheduledWorkflows:
208
+ """
209
+ Retrieves a specific scheduled workflow by scheduled run trigger ID.
223
210
 
224
211
  Args:
225
- scheduled (Union[str, ScheduledWorkflows]): The scheduled workflow trigger ID or ScheduledWorkflows instance to retrieve.
212
+ scheduled (str): The scheduled workflow trigger ID to retrieve.
226
213
 
227
214
  Returns:
228
215
  ScheduledWorkflows: The requested scheduled workflow instance.
229
216
  """
230
- return await self._client.rest.aio_get_schedule(
231
- scheduled.metadata.id
232
- if isinstance(scheduled, ScheduledWorkflows)
233
- else scheduled
234
- )
217
+ return self._run_async_from_sync(self.aio_get, scheduled_id)