hatchet-sdk 0.40.0a8__py3-none-any.whl → 0.41.0__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.
- hatchet_sdk/clients/admin.py +129 -59
- hatchet_sdk/clients/dispatcher/action_listener.py +25 -2
- hatchet_sdk/clients/events.py +91 -52
- hatchet_sdk/clients/rest/__init__.py +21 -0
- hatchet_sdk/clients/rest/api/api_token_api.py +12 -9
- hatchet_sdk/clients/rest/api/default_api.py +24 -18
- hatchet_sdk/clients/rest/api/event_api.py +32 -24
- hatchet_sdk/clients/rest/api/github_api.py +4 -3
- hatchet_sdk/clients/rest/api/log_api.py +4 -3
- hatchet_sdk/clients/rest/api/metadata_api.py +12 -9
- hatchet_sdk/clients/rest/api/rate_limits_api.py +7 -4
- hatchet_sdk/clients/rest/api/slack_api.py +8 -6
- hatchet_sdk/clients/rest/api/sns_api.py +12 -9
- hatchet_sdk/clients/rest/api/step_run_api.py +28 -21
- hatchet_sdk/clients/rest/api/tenant_api.py +67 -49
- hatchet_sdk/clients/rest/api/user_api.py +24 -18
- hatchet_sdk/clients/rest/api/worker_api.py +12 -9
- hatchet_sdk/clients/rest/api/workflow_api.py +3073 -936
- hatchet_sdk/clients/rest/api/workflow_run_api.py +669 -21
- hatchet_sdk/clients/rest/api_client.py +34 -11
- hatchet_sdk/clients/rest/configuration.py +161 -36
- hatchet_sdk/clients/rest/models/__init__.py +21 -0
- hatchet_sdk/clients/rest/models/api_errors.py +3 -3
- hatchet_sdk/clients/rest/models/bulk_create_event_request.py +3 -3
- hatchet_sdk/clients/rest/models/bulk_create_event_response.py +3 -3
- hatchet_sdk/clients/{cloud_rest/models/managed_worker_create_request_build_config_steps_inner.py → rest/models/create_cron_workflow_trigger_request.py} +18 -14
- hatchet_sdk/clients/{cloud_rest/models/github_app_list_installations200_response_rows_inner.py → rest/models/cron_workflows.py} +54 -21
- hatchet_sdk/clients/{cloud_rest/models/log_list200_response.py → rest/models/cron_workflows_list.py} +13 -22
- hatchet_sdk/clients/rest/models/cron_workflows_order_by_field.py +37 -0
- hatchet_sdk/clients/rest/models/event_list.py +3 -3
- hatchet_sdk/clients/rest/models/get_step_run_diff_response.py +3 -3
- hatchet_sdk/clients/rest/models/job.py +3 -3
- hatchet_sdk/clients/rest/models/job_run.py +3 -3
- hatchet_sdk/clients/rest/models/list_api_tokens_response.py +3 -3
- hatchet_sdk/clients/rest/models/list_pull_requests_response.py +3 -3
- hatchet_sdk/clients/rest/models/list_slack_webhooks.py +3 -3
- hatchet_sdk/clients/rest/models/list_sns_integrations.py +3 -3
- hatchet_sdk/clients/rest/models/log_line_list.py +3 -3
- hatchet_sdk/clients/rest/models/rate_limit_list.py +3 -3
- hatchet_sdk/clients/rest/models/replay_workflow_runs_response.py +3 -3
- hatchet_sdk/clients/{cloud_rest/models/log_list200_response_rows_inner.py → rest/models/schedule_workflow_run_request.py} +12 -12
- hatchet_sdk/clients/rest/models/scheduled_run_status.py +42 -0
- hatchet_sdk/clients/rest/models/scheduled_workflows.py +153 -0
- hatchet_sdk/clients/{cloud_rest/models/managed_worker_list200_response.py → rest/models/scheduled_workflows_list.py} +13 -22
- hatchet_sdk/clients/rest/models/scheduled_workflows_order_by_field.py +37 -0
- hatchet_sdk/clients/rest/models/step_run_archive_list.py +3 -3
- hatchet_sdk/clients/rest/models/step_run_event_list.py +3 -3
- hatchet_sdk/clients/rest/models/tenant_alert_email_group_list.py +3 -3
- hatchet_sdk/clients/rest/models/tenant_invite_list.py +3 -3
- hatchet_sdk/clients/rest/models/tenant_list.py +3 -3
- hatchet_sdk/clients/rest/models/tenant_member_list.py +3 -3
- hatchet_sdk/clients/rest/models/tenant_queue_metrics.py +16 -0
- hatchet_sdk/clients/rest/models/tenant_resource_policy.py +3 -3
- hatchet_sdk/clients/rest/models/tenant_step_run_queue_metrics.py +1 -1
- hatchet_sdk/clients/rest/models/user_tenant_memberships_list.py +3 -3
- hatchet_sdk/clients/rest/models/webhook_worker_list_response.py +3 -3
- hatchet_sdk/clients/rest/models/webhook_worker_request_list_response.py +3 -3
- hatchet_sdk/clients/rest/models/worker.py +20 -9
- hatchet_sdk/clients/rest/models/worker_list.py +3 -3
- hatchet_sdk/clients/{cloud_rest/models/tenant_billing_state_get200_response_payment_methods_inner.py → rest/models/worker_runtime_info.py} +23 -19
- hatchet_sdk/clients/rest/models/worker_runtime_sdks.py +38 -0
- hatchet_sdk/clients/rest/models/workflow.py +9 -9
- hatchet_sdk/clients/rest/models/workflow_list.py +3 -3
- hatchet_sdk/clients/rest/models/workflow_run.py +3 -3
- hatchet_sdk/clients/rest/models/workflow_run_list.py +3 -3
- hatchet_sdk/clients/rest/models/workflow_run_shape.py +3 -3
- hatchet_sdk/clients/rest/models/workflow_runs_metrics.py +1 -5
- hatchet_sdk/clients/rest/models/workflow_triggers.py +6 -6
- hatchet_sdk/clients/rest/models/workflow_version.py +3 -3
- hatchet_sdk/clients/rest/rest.py +3 -3
- hatchet_sdk/clients/rest_client.py +200 -21
- hatchet_sdk/contracts/dispatcher_pb2.pyi +2 -0
- hatchet_sdk/contracts/events_pb2.pyi +2 -0
- hatchet_sdk/contracts/workflows_pb2.pyi +2 -0
- hatchet_sdk/features/cron.py +286 -0
- hatchet_sdk/features/scheduled.py +248 -0
- hatchet_sdk/hatchet.py +71 -79
- hatchet_sdk/loader.py +37 -14
- hatchet_sdk/utils/serialization.py +15 -0
- hatchet_sdk/utils/tracing.py +67 -0
- hatchet_sdk/worker/runner/runner.py +158 -112
- hatchet_sdk/worker/worker.py +1 -17
- {hatchet_sdk-0.40.0a8.dist-info → hatchet_sdk-0.41.0.dist-info}/METADATA +8 -2
- {hatchet_sdk-0.40.0a8.dist-info → hatchet_sdk-0.41.0.dist-info}/RECORD +86 -140
- {hatchet_sdk-0.40.0a8.dist-info → hatchet_sdk-0.41.0.dist-info}/entry_points.txt +0 -1
- hatchet_sdk/clients/cloud_rest/__init__.py +0 -186
- hatchet_sdk/clients/cloud_rest/api/__init__.py +0 -14
- hatchet_sdk/clients/cloud_rest/api/billing_api.py +0 -819
- hatchet_sdk/clients/cloud_rest/api/build_api.py +0 -298
- hatchet_sdk/clients/cloud_rest/api/feature_flags_api.py +0 -295
- hatchet_sdk/clients/cloud_rest/api/github_api.py +0 -1347
- hatchet_sdk/clients/cloud_rest/api/log_api.py +0 -971
- hatchet_sdk/clients/cloud_rest/api/managed_worker_api.py +0 -2546
- hatchet_sdk/clients/cloud_rest/api/metadata_api.py +0 -265
- hatchet_sdk/clients/cloud_rest/api/metrics_api.py +0 -1026
- hatchet_sdk/clients/cloud_rest/api/tenant_api.py +0 -301
- hatchet_sdk/clients/cloud_rest/api/user_api.py +0 -473
- hatchet_sdk/clients/cloud_rest/api/workflow_api.py +0 -369
- hatchet_sdk/clients/cloud_rest/api_client.py +0 -727
- hatchet_sdk/clients/cloud_rest/api_response.py +0 -22
- hatchet_sdk/clients/cloud_rest/configuration.py +0 -488
- hatchet_sdk/clients/cloud_rest/exceptions.py +0 -200
- hatchet_sdk/clients/cloud_rest/models/__init__.py +0 -157
- hatchet_sdk/clients/cloud_rest/models/billing_portal_link_get200_response.py +0 -85
- hatchet_sdk/clients/cloud_rest/models/build_get200_response.py +0 -121
- hatchet_sdk/clients/cloud_rest/models/github_app_list_branches200_response_inner.py +0 -86
- hatchet_sdk/clients/cloud_rest/models/github_app_list_installations200_response.py +0 -119
- hatchet_sdk/clients/cloud_rest/models/github_app_list_installations200_response_pagination.py +0 -95
- hatchet_sdk/clients/cloud_rest/models/github_app_list_installations200_response_rows_inner_metadata.py +0 -98
- hatchet_sdk/clients/cloud_rest/models/github_app_list_repos200_response_inner.py +0 -86
- hatchet_sdk/clients/cloud_rest/models/infra_as_code_create_request.py +0 -107
- hatchet_sdk/clients/cloud_rest/models/log_create_request_inner.py +0 -136
- hatchet_sdk/clients/cloud_rest/models/log_create_request_inner_event.py +0 -83
- hatchet_sdk/clients/cloud_rest/models/log_create_request_inner_fly.py +0 -100
- hatchet_sdk/clients/cloud_rest/models/log_create_request_inner_fly_app.py +0 -86
- hatchet_sdk/clients/cloud_rest/models/log_create_request_inner_log.py +0 -83
- hatchet_sdk/clients/cloud_rest/models/managed_worker_create_request.py +0 -128
- hatchet_sdk/clients/cloud_rest/models/managed_worker_create_request_build_config.py +0 -121
- hatchet_sdk/clients/cloud_rest/models/managed_worker_create_request_runtime_config.py +0 -166
- hatchet_sdk/clients/cloud_rest/models/managed_worker_events_list200_response.py +0 -119
- hatchet_sdk/clients/cloud_rest/models/managed_worker_events_list200_response_rows_inner.py +0 -117
- hatchet_sdk/clients/cloud_rest/models/managed_worker_instances_list200_response.py +0 -119
- hatchet_sdk/clients/cloud_rest/models/managed_worker_instances_list200_response_rows_inner.py +0 -113
- hatchet_sdk/clients/cloud_rest/models/managed_worker_list200_response_rows_inner.py +0 -154
- hatchet_sdk/clients/cloud_rest/models/managed_worker_list200_response_rows_inner_build_config.py +0 -151
- hatchet_sdk/clients/cloud_rest/models/managed_worker_list200_response_rows_inner_build_config_steps_inner.py +0 -109
- hatchet_sdk/clients/cloud_rest/models/managed_worker_list200_response_rows_inner_runtime_configs_inner.py +0 -171
- hatchet_sdk/clients/cloud_rest/models/managed_worker_update_request.py +0 -131
- hatchet_sdk/clients/cloud_rest/models/metadata_get200_response.py +0 -101
- hatchet_sdk/clients/cloud_rest/models/metadata_get400_response.py +0 -105
- hatchet_sdk/clients/cloud_rest/models/metadata_get400_response_errors_inner.py +0 -102
- hatchet_sdk/clients/cloud_rest/models/metrics_cpu_get200_response_inner.py +0 -108
- hatchet_sdk/clients/cloud_rest/models/metrics_cpu_get200_response_inner_histograms_inner.py +0 -102
- hatchet_sdk/clients/cloud_rest/models/metrics_cpu_get200_response_inner_histograms_inner_histogram.py +0 -113
- hatchet_sdk/clients/cloud_rest/models/metrics_cpu_get200_response_inner_histograms_inner_histogram_buckets_inner.py +0 -93
- hatchet_sdk/clients/cloud_rest/models/runtime_config_list_actions200_response.py +0 -83
- hatchet_sdk/clients/cloud_rest/models/subscription_upsert200_response.py +0 -114
- hatchet_sdk/clients/cloud_rest/models/subscription_upsert_request.py +0 -88
- hatchet_sdk/clients/cloud_rest/models/tenant_billing_state_get200_response.py +0 -170
- hatchet_sdk/clients/cloud_rest/models/tenant_billing_state_get200_response_coupons_inner.py +0 -137
- hatchet_sdk/clients/cloud_rest/models/tenant_billing_state_get200_response_plans_inner.py +0 -103
- hatchet_sdk/clients/cloud_rest/models/tenant_billing_state_get200_response_subscription.py +0 -114
- hatchet_sdk/clients/cloud_rest/models/workflow_run_events_get_metrics200_response.py +0 -107
- hatchet_sdk/clients/cloud_rest/models/workflow_run_events_get_metrics200_response_results_inner.py +0 -105
- hatchet_sdk/clients/cloud_rest/rest.py +0 -182
- hatchet_sdk/compute/__init__.py +0 -0
- hatchet_sdk/compute/configs.py +0 -34
- hatchet_sdk/compute/managed_compute.py +0 -111
- {hatchet_sdk-0.40.0a8.dist-info → hatchet_sdk-0.41.0.dist-info}/WHEEL +0 -0
hatchet_sdk/clients/rest/rest.py
CHANGED
|
@@ -81,7 +81,7 @@ class RESTClientObject:
|
|
|
81
81
|
self.retry_client = aiohttp_retry.RetryClient(
|
|
82
82
|
client_session=self.pool_manager,
|
|
83
83
|
retry_options=aiohttp_retry.ExponentialRetry(
|
|
84
|
-
attempts=retries, factor=
|
|
84
|
+
attempts=retries, factor=2.0, start_timeout=0.1, max_timeout=120.0
|
|
85
85
|
),
|
|
86
86
|
)
|
|
87
87
|
else:
|
|
@@ -164,10 +164,10 @@ class RESTClientObject:
|
|
|
164
164
|
data.add_field(k, v)
|
|
165
165
|
args["data"] = data
|
|
166
166
|
|
|
167
|
-
# Pass a `bytes` parameter directly in the body to support
|
|
167
|
+
# Pass a `bytes` or `str` parameter directly in the body to support
|
|
168
168
|
# other content types than Json when `body` argument is provided
|
|
169
169
|
# in serialized form
|
|
170
|
-
elif isinstance(body, bytes):
|
|
170
|
+
elif isinstance(body, str) or isinstance(body, bytes):
|
|
171
171
|
args["data"] = body
|
|
172
172
|
else:
|
|
173
173
|
# Cannot generate the request from given parameters
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import asyncio
|
|
2
2
|
import atexit
|
|
3
|
+
import datetime
|
|
3
4
|
import threading
|
|
4
|
-
from typing import Any
|
|
5
|
+
from typing import Any, Coroutine, List
|
|
6
|
+
|
|
7
|
+
from pydantic import StrictInt
|
|
5
8
|
|
|
6
|
-
from hatchet_sdk.clients.cloud_rest.api.managed_worker_api import ManagedWorkerApi
|
|
7
|
-
from hatchet_sdk.clients.cloud_rest.api_client import ApiClient as CloudApiClient
|
|
8
|
-
from hatchet_sdk.clients.cloud_rest.configuration import (
|
|
9
|
-
Configuration as CloudConfiguration,
|
|
10
|
-
)
|
|
11
9
|
from hatchet_sdk.clients.rest.api.event_api import EventApi
|
|
12
10
|
from hatchet_sdk.clients.rest.api.log_api import LogApi
|
|
13
11
|
from hatchet_sdk.clients.rest.api.step_run_api import StepRunApi
|
|
@@ -17,6 +15,13 @@ from hatchet_sdk.clients.rest.api.workflow_runs_api import WorkflowRunsApi
|
|
|
17
15
|
from hatchet_sdk.clients.rest.api_client import ApiClient
|
|
18
16
|
from hatchet_sdk.clients.rest.configuration import Configuration
|
|
19
17
|
from hatchet_sdk.clients.rest.models import TriggerWorkflowRunRequest
|
|
18
|
+
from hatchet_sdk.clients.rest.models.create_cron_workflow_trigger_request import (
|
|
19
|
+
CreateCronWorkflowTriggerRequest,
|
|
20
|
+
)
|
|
21
|
+
from hatchet_sdk.clients.rest.models.cron_workflows import CronWorkflows
|
|
22
|
+
from hatchet_sdk.clients.rest.models.cron_workflows_order_by_field import (
|
|
23
|
+
CronWorkflowsOrderByField,
|
|
24
|
+
)
|
|
20
25
|
from hatchet_sdk.clients.rest.models.event_list import EventList
|
|
21
26
|
from hatchet_sdk.clients.rest.models.event_order_by_direction import (
|
|
22
27
|
EventOrderByDirection,
|
|
@@ -35,6 +40,13 @@ from hatchet_sdk.clients.rest.models.replay_workflow_runs_request import (
|
|
|
35
40
|
from hatchet_sdk.clients.rest.models.replay_workflow_runs_response import (
|
|
36
41
|
ReplayWorkflowRunsResponse,
|
|
37
42
|
)
|
|
43
|
+
from hatchet_sdk.clients.rest.models.schedule_workflow_run_request import (
|
|
44
|
+
ScheduleWorkflowRunRequest,
|
|
45
|
+
)
|
|
46
|
+
from hatchet_sdk.clients.rest.models.scheduled_workflows import ScheduledWorkflows
|
|
47
|
+
from hatchet_sdk.clients.rest.models.scheduled_workflows_order_by_field import (
|
|
48
|
+
ScheduledWorkflowsOrderByField,
|
|
49
|
+
)
|
|
38
50
|
from hatchet_sdk.clients.rest.models.workflow import Workflow
|
|
39
51
|
from hatchet_sdk.clients.rest.models.workflow_kind import WorkflowKind
|
|
40
52
|
from hatchet_sdk.clients.rest.models.workflow_list import WorkflowList
|
|
@@ -65,15 +77,7 @@ class AsyncRestApi:
|
|
|
65
77
|
access_token=api_key,
|
|
66
78
|
)
|
|
67
79
|
|
|
68
|
-
self.cloud_config = CloudConfiguration(
|
|
69
|
-
host=host,
|
|
70
|
-
access_token=api_key,
|
|
71
|
-
)
|
|
72
|
-
|
|
73
80
|
self._api_client = None
|
|
74
|
-
self._cloud_api_client = None
|
|
75
|
-
self._managed_worker_api = None
|
|
76
|
-
|
|
77
81
|
self._workflow_api = None
|
|
78
82
|
self._workflow_run_api = None
|
|
79
83
|
self._step_run_api = None
|
|
@@ -84,15 +88,8 @@ class AsyncRestApi:
|
|
|
84
88
|
def api_client(self):
|
|
85
89
|
if self._api_client is None:
|
|
86
90
|
self._api_client = ApiClient(configuration=self.config)
|
|
87
|
-
self._cloud_api_client = CloudApiClient(configuration=self.cloud_config)
|
|
88
91
|
return self._api_client
|
|
89
92
|
|
|
90
|
-
@property
|
|
91
|
-
def managed_worker_api(self):
|
|
92
|
-
if self._managed_worker_api is None:
|
|
93
|
-
self._managed_worker_api = ManagedWorkerApi(self.api_client)
|
|
94
|
-
return self._managed_worker_api
|
|
95
|
-
|
|
96
93
|
@property
|
|
97
94
|
def workflow_api(self):
|
|
98
95
|
if self._workflow_api is None:
|
|
@@ -223,9 +220,112 @@ class AsyncRestApi:
|
|
|
223
220
|
version=version,
|
|
224
221
|
trigger_workflow_run_request=TriggerWorkflowRunRequest(
|
|
225
222
|
input=input,
|
|
223
|
+
additional_metadata=additional_metadata,
|
|
224
|
+
),
|
|
225
|
+
)
|
|
226
|
+
|
|
227
|
+
async def cron_create(
|
|
228
|
+
self,
|
|
229
|
+
workflow_name: str,
|
|
230
|
+
cron_name: str,
|
|
231
|
+
expression: str,
|
|
232
|
+
input: dict[str, Any],
|
|
233
|
+
additional_metadata: dict[str, str],
|
|
234
|
+
):
|
|
235
|
+
return await self.workflow_run_api.cron_workflow_trigger_create(
|
|
236
|
+
tenant=self.tenant_id,
|
|
237
|
+
workflow=workflow_name,
|
|
238
|
+
create_cron_workflow_trigger_request=CreateCronWorkflowTriggerRequest(
|
|
239
|
+
cronName=cron_name,
|
|
240
|
+
expression=expression,
|
|
241
|
+
input=input,
|
|
242
|
+
additional_metadata=additional_metadata,
|
|
243
|
+
),
|
|
244
|
+
)
|
|
245
|
+
|
|
246
|
+
async def cron_delete(self, cron_trigger_id: str):
|
|
247
|
+
return await self.workflow_api.workflow_cron_delete(
|
|
248
|
+
tenant=self.tenant_id,
|
|
249
|
+
cron_workflow=cron_trigger_id,
|
|
250
|
+
)
|
|
251
|
+
|
|
252
|
+
async def cron_list(
|
|
253
|
+
self,
|
|
254
|
+
offset: StrictInt | None = None,
|
|
255
|
+
limit: StrictInt | None = None,
|
|
256
|
+
workflow_id: str | None = None,
|
|
257
|
+
additional_metadata: list[str] | None = None,
|
|
258
|
+
order_by_field: CronWorkflowsOrderByField | None = None,
|
|
259
|
+
order_by_direction: WorkflowRunOrderByDirection | None = None,
|
|
260
|
+
):
|
|
261
|
+
return await self.workflow_api.cron_workflow_list(
|
|
262
|
+
tenant=self.tenant_id,
|
|
263
|
+
offset=offset,
|
|
264
|
+
limit=limit,
|
|
265
|
+
workflow_id=workflow_id,
|
|
266
|
+
additional_metadata=additional_metadata,
|
|
267
|
+
order_by_field=order_by_field,
|
|
268
|
+
order_by_direction=order_by_direction,
|
|
269
|
+
)
|
|
270
|
+
|
|
271
|
+
async def cron_get(self, cron_trigger_id: str):
|
|
272
|
+
return await self.workflow_api.workflow_cron_get(
|
|
273
|
+
tenant=self.tenant_id,
|
|
274
|
+
cron_workflow=cron_trigger_id,
|
|
275
|
+
)
|
|
276
|
+
|
|
277
|
+
async def schedule_create(
|
|
278
|
+
self,
|
|
279
|
+
name: str,
|
|
280
|
+
trigger_at: datetime.datetime,
|
|
281
|
+
input: dict[str, Any],
|
|
282
|
+
additional_metadata: dict[str, str],
|
|
283
|
+
):
|
|
284
|
+
return await self.workflow_run_api.scheduled_workflow_run_create(
|
|
285
|
+
tenant=self.tenant_id,
|
|
286
|
+
workflow=name,
|
|
287
|
+
create_schedule_workflow_trigger_request=ScheduleWorkflowRunRequest(
|
|
288
|
+
triggerAt=trigger_at,
|
|
289
|
+
input=input,
|
|
290
|
+
additional_metadata=additional_metadata,
|
|
226
291
|
),
|
|
227
292
|
)
|
|
228
293
|
|
|
294
|
+
async def schedule_delete(self, scheduled_trigger_id: str):
|
|
295
|
+
return await self.workflow_api.workflow_scheduled_delete(
|
|
296
|
+
tenant=self.tenant_id,
|
|
297
|
+
scheduled_workflow_run=scheduled_trigger_id,
|
|
298
|
+
)
|
|
299
|
+
|
|
300
|
+
async def schedule_list(
|
|
301
|
+
self,
|
|
302
|
+
offset: StrictInt | None = None,
|
|
303
|
+
limit: StrictInt | None = None,
|
|
304
|
+
workflow_id: str | None = None,
|
|
305
|
+
additional_metadata: list[str] | None = None,
|
|
306
|
+
parent_workflow_run_id: str | None = None,
|
|
307
|
+
parent_step_run_id: str | None = None,
|
|
308
|
+
order_by_field: ScheduledWorkflowsOrderByField | None = None,
|
|
309
|
+
order_by_direction: WorkflowRunOrderByDirection | None = None,
|
|
310
|
+
):
|
|
311
|
+
return await self.workflow_api.workflow_scheduled_list(
|
|
312
|
+
tenant=self.tenant_id,
|
|
313
|
+
offset=offset,
|
|
314
|
+
limit=limit,
|
|
315
|
+
workflow_id=workflow_id,
|
|
316
|
+
parent_workflow_run_id=parent_workflow_run_id,
|
|
317
|
+
parent_step_run_id=parent_step_run_id,
|
|
318
|
+
additional_metadata=additional_metadata,
|
|
319
|
+
order_by_field=order_by_field,
|
|
320
|
+
order_by_direction=order_by_direction,
|
|
321
|
+
)
|
|
322
|
+
|
|
323
|
+
async def schedule_get(self, scheduled_trigger_id: str):
|
|
324
|
+
return await self.workflow_api.workflow_scheduled_get(
|
|
325
|
+
tenant=self.tenant_id,
|
|
326
|
+
scheduled_workflow_run=scheduled_trigger_id,
|
|
327
|
+
)
|
|
328
|
+
|
|
229
329
|
async def list_logs(
|
|
230
330
|
self,
|
|
231
331
|
step_run_id: str,
|
|
@@ -380,6 +480,85 @@ class RestApi:
|
|
|
380
480
|
)
|
|
381
481
|
)
|
|
382
482
|
|
|
483
|
+
def cron_create(
|
|
484
|
+
self,
|
|
485
|
+
workflow_name: str,
|
|
486
|
+
cron_name: str,
|
|
487
|
+
expression: str,
|
|
488
|
+
input: dict[str, Any],
|
|
489
|
+
additional_metadata: dict[str, str],
|
|
490
|
+
) -> CronWorkflows:
|
|
491
|
+
return self._run_coroutine(
|
|
492
|
+
self.aio.cron_create(
|
|
493
|
+
workflow_name, cron_name, expression, input, additional_metadata
|
|
494
|
+
)
|
|
495
|
+
)
|
|
496
|
+
|
|
497
|
+
def cron_delete(self, cron_trigger_id: str):
|
|
498
|
+
return self._run_coroutine(self.aio.cron_delete(cron_trigger_id))
|
|
499
|
+
|
|
500
|
+
def cron_list(
|
|
501
|
+
self,
|
|
502
|
+
offset: int | None = None,
|
|
503
|
+
limit: int | None = None,
|
|
504
|
+
workflow_id: str | None = None,
|
|
505
|
+
additional_metadata: list[str] | None = None,
|
|
506
|
+
order_by_field: CronWorkflowsOrderByField | None = None,
|
|
507
|
+
order_by_direction: WorkflowRunOrderByDirection | None = None,
|
|
508
|
+
):
|
|
509
|
+
return self._run_coroutine(
|
|
510
|
+
self.aio.cron_list(
|
|
511
|
+
offset,
|
|
512
|
+
limit,
|
|
513
|
+
workflow_id,
|
|
514
|
+
additional_metadata,
|
|
515
|
+
order_by_field,
|
|
516
|
+
order_by_direction,
|
|
517
|
+
)
|
|
518
|
+
)
|
|
519
|
+
|
|
520
|
+
def cron_get(self, cron_trigger_id: str):
|
|
521
|
+
return self._run_coroutine(self.aio.cron_get(cron_trigger_id))
|
|
522
|
+
|
|
523
|
+
def schedule_create(
|
|
524
|
+
self,
|
|
525
|
+
workflow_name: str,
|
|
526
|
+
trigger_at: datetime.datetime,
|
|
527
|
+
input: dict[str, Any],
|
|
528
|
+
additional_metadata: dict[str, str],
|
|
529
|
+
):
|
|
530
|
+
return self._run_coroutine(
|
|
531
|
+
self.aio.schedule_create(
|
|
532
|
+
workflow_name, trigger_at, input, additional_metadata
|
|
533
|
+
)
|
|
534
|
+
)
|
|
535
|
+
|
|
536
|
+
def schedule_delete(self, scheduled_trigger_id: str):
|
|
537
|
+
return self._run_coroutine(self.aio.schedule_delete(scheduled_trigger_id))
|
|
538
|
+
|
|
539
|
+
def schedule_list(
|
|
540
|
+
self,
|
|
541
|
+
offset: int | None = None,
|
|
542
|
+
limit: int | None = None,
|
|
543
|
+
workflow_id: str | None = None,
|
|
544
|
+
additional_metadata: list[str] | None = None,
|
|
545
|
+
order_by_field: CronWorkflowsOrderByField | None = None,
|
|
546
|
+
order_by_direction: WorkflowRunOrderByDirection | None = None,
|
|
547
|
+
):
|
|
548
|
+
return self._run_coroutine(
|
|
549
|
+
self.aio.schedule_list(
|
|
550
|
+
offset,
|
|
551
|
+
limit,
|
|
552
|
+
workflow_id,
|
|
553
|
+
additional_metadata,
|
|
554
|
+
order_by_field,
|
|
555
|
+
order_by_direction,
|
|
556
|
+
)
|
|
557
|
+
)
|
|
558
|
+
|
|
559
|
+
def schedule_get(self, scheduled_trigger_id: str):
|
|
560
|
+
return self._run_coroutine(self.aio.schedule_get(scheduled_trigger_id))
|
|
561
|
+
|
|
383
562
|
def list_logs(
|
|
384
563
|
self,
|
|
385
564
|
step_run_id: str,
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
from typing import Union
|
|
2
|
+
|
|
3
|
+
from pydantic import BaseModel, field_validator
|
|
4
|
+
|
|
5
|
+
from hatchet_sdk.client import Client
|
|
6
|
+
from hatchet_sdk.clients.rest.models.cron_workflows import CronWorkflows
|
|
7
|
+
from hatchet_sdk.clients.rest.models.cron_workflows_list import CronWorkflowsList
|
|
8
|
+
from hatchet_sdk.clients.rest.models.cron_workflows_order_by_field import (
|
|
9
|
+
CronWorkflowsOrderByField,
|
|
10
|
+
)
|
|
11
|
+
from hatchet_sdk.clients.rest.models.workflow_run_order_by_direction import (
|
|
12
|
+
WorkflowRunOrderByDirection,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class CreateCronTriggerInput(BaseModel):
|
|
17
|
+
"""
|
|
18
|
+
Schema for creating a workflow run triggered by a cron.
|
|
19
|
+
|
|
20
|
+
Attributes:
|
|
21
|
+
expression (str): The cron expression defining the schedule.
|
|
22
|
+
input (dict): The input data for the cron workflow.
|
|
23
|
+
additional_metadata (dict[str, str]): Additional metadata associated with the cron trigger (e.g. {"key1": "value1", "key2": "value2"}).
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
expression: str = None
|
|
27
|
+
input: dict = {}
|
|
28
|
+
additional_metadata: dict[str, str] = {}
|
|
29
|
+
|
|
30
|
+
@field_validator("expression")
|
|
31
|
+
def validate_cron_expression(cls, v):
|
|
32
|
+
"""
|
|
33
|
+
Validates the cron expression to ensure it adheres to the expected format.
|
|
34
|
+
|
|
35
|
+
Args:
|
|
36
|
+
v (str): The cron expression to validate.
|
|
37
|
+
|
|
38
|
+
Raises:
|
|
39
|
+
ValueError: If the expression is invalid.
|
|
40
|
+
|
|
41
|
+
Returns:
|
|
42
|
+
str: The validated cron expression.
|
|
43
|
+
"""
|
|
44
|
+
if not v:
|
|
45
|
+
raise ValueError("Cron expression is required")
|
|
46
|
+
|
|
47
|
+
parts = v.split()
|
|
48
|
+
if len(parts) != 5:
|
|
49
|
+
raise ValueError(
|
|
50
|
+
"Cron expression must have 5 parts: minute hour day month weekday"
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
for part in parts:
|
|
54
|
+
if not (
|
|
55
|
+
part == "*"
|
|
56
|
+
or part.replace("*/", "").replace("-", "").replace(",", "").isdigit()
|
|
57
|
+
):
|
|
58
|
+
raise ValueError(f"Invalid cron expression part: {part}")
|
|
59
|
+
|
|
60
|
+
return v
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
class CronClient:
|
|
64
|
+
"""
|
|
65
|
+
Client for managing workflow cron triggers synchronously.
|
|
66
|
+
|
|
67
|
+
Attributes:
|
|
68
|
+
_client (Client): The underlying client used to interact with the REST API.
|
|
69
|
+
aio (CronClientAsync): Asynchronous counterpart of CronClient.
|
|
70
|
+
"""
|
|
71
|
+
|
|
72
|
+
_client: Client
|
|
73
|
+
|
|
74
|
+
def __init__(self, _client: Client):
|
|
75
|
+
"""
|
|
76
|
+
Initializes the CronClient with a given Client instance.
|
|
77
|
+
|
|
78
|
+
Args:
|
|
79
|
+
_client (Client): The client instance to be used for REST interactions.
|
|
80
|
+
"""
|
|
81
|
+
self._client = _client
|
|
82
|
+
self.aio = CronClientAsync(_client)
|
|
83
|
+
|
|
84
|
+
def create(
|
|
85
|
+
self,
|
|
86
|
+
workflow_name: str,
|
|
87
|
+
cron_name: str,
|
|
88
|
+
expression: str,
|
|
89
|
+
input: dict,
|
|
90
|
+
additional_metadata: dict[str, str],
|
|
91
|
+
) -> CronWorkflows:
|
|
92
|
+
"""
|
|
93
|
+
Creates a new workflow cron trigger.
|
|
94
|
+
|
|
95
|
+
Args:
|
|
96
|
+
workflow_name (str): The name of the workflow to trigger.
|
|
97
|
+
cron_name (str): The name of the cron trigger.
|
|
98
|
+
expression (str): The cron expression defining the schedule.
|
|
99
|
+
input (dict): The input data for the cron workflow.
|
|
100
|
+
additional_metadata (dict[str, str]): Additional metadata associated with the cron trigger (e.g. {"key1": "value1", "key2": "value2"}).
|
|
101
|
+
|
|
102
|
+
Returns:
|
|
103
|
+
CronWorkflows: The created cron workflow instance.
|
|
104
|
+
"""
|
|
105
|
+
validated_input = CreateCronTriggerInput(
|
|
106
|
+
expression=expression, input=input, additional_metadata=additional_metadata
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
return self._client.rest.cron_create(
|
|
110
|
+
workflow_name,
|
|
111
|
+
cron_name,
|
|
112
|
+
validated_input.expression,
|
|
113
|
+
validated_input.input,
|
|
114
|
+
validated_input.additional_metadata,
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
def delete(self, cron_trigger: Union[str, CronWorkflows]) -> None:
|
|
118
|
+
"""
|
|
119
|
+
Deletes a workflow cron trigger.
|
|
120
|
+
|
|
121
|
+
Args:
|
|
122
|
+
cron_trigger (Union[str, CronWorkflows]): The cron trigger ID or CronWorkflows instance to delete.
|
|
123
|
+
"""
|
|
124
|
+
id_ = cron_trigger
|
|
125
|
+
if isinstance(cron_trigger, CronWorkflows):
|
|
126
|
+
id_ = cron_trigger.metadata.id
|
|
127
|
+
self._client.rest.cron_delete(id_)
|
|
128
|
+
|
|
129
|
+
def list(
|
|
130
|
+
self,
|
|
131
|
+
offset: int | None = None,
|
|
132
|
+
limit: int | None = None,
|
|
133
|
+
workflow_id: str | None = None,
|
|
134
|
+
additional_metadata: list[str] | None = None,
|
|
135
|
+
order_by_field: CronWorkflowsOrderByField | None = None,
|
|
136
|
+
order_by_direction: WorkflowRunOrderByDirection | None = None,
|
|
137
|
+
) -> CronWorkflowsList:
|
|
138
|
+
"""
|
|
139
|
+
Retrieves a list of all workflow cron triggers matching the criteria.
|
|
140
|
+
|
|
141
|
+
Args:
|
|
142
|
+
offset (int | None): The offset to start the list from.
|
|
143
|
+
limit (int | None): The maximum number of items to return.
|
|
144
|
+
workflow_id (str | None): The ID of the workflow to filter by.
|
|
145
|
+
additional_metadata (list[str] | None): Filter by additional metadata keys (e.g. ["key1:value1", "key2:value2"]).
|
|
146
|
+
order_by_field (CronWorkflowsOrderByField | None): The field to order the list by.
|
|
147
|
+
order_by_direction (WorkflowRunOrderByDirection | None): The direction to order the list by.
|
|
148
|
+
|
|
149
|
+
Returns:
|
|
150
|
+
CronWorkflowsList: A list of cron workflows.
|
|
151
|
+
"""
|
|
152
|
+
return self._client.rest.cron_list(
|
|
153
|
+
offset=offset,
|
|
154
|
+
limit=limit,
|
|
155
|
+
workflow_id=workflow_id,
|
|
156
|
+
additional_metadata=additional_metadata,
|
|
157
|
+
order_by_field=order_by_field,
|
|
158
|
+
order_by_direction=order_by_direction,
|
|
159
|
+
)
|
|
160
|
+
|
|
161
|
+
def get(self, cron_trigger: Union[str, CronWorkflows]) -> CronWorkflows:
|
|
162
|
+
"""
|
|
163
|
+
Retrieves a specific workflow cron trigger by ID.
|
|
164
|
+
|
|
165
|
+
Args:
|
|
166
|
+
cron_trigger (Union[str, CronWorkflows]): The cron trigger ID or CronWorkflows instance to retrieve.
|
|
167
|
+
|
|
168
|
+
Returns:
|
|
169
|
+
CronWorkflows: The requested cron workflow instance.
|
|
170
|
+
"""
|
|
171
|
+
id_ = cron_trigger
|
|
172
|
+
if isinstance(cron_trigger, CronWorkflows):
|
|
173
|
+
id_ = cron_trigger.metadata.id
|
|
174
|
+
return self._client.rest.cron_get(id_)
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
class CronClientAsync:
|
|
178
|
+
"""
|
|
179
|
+
Asynchronous client for managing workflow cron triggers.
|
|
180
|
+
|
|
181
|
+
Attributes:
|
|
182
|
+
_client (Client): The underlying client used to interact with the REST API asynchronously.
|
|
183
|
+
"""
|
|
184
|
+
|
|
185
|
+
_client: Client
|
|
186
|
+
|
|
187
|
+
def __init__(self, _client: Client):
|
|
188
|
+
"""
|
|
189
|
+
Initializes the CronClientAsync with a given Client instance.
|
|
190
|
+
|
|
191
|
+
Args:
|
|
192
|
+
_client (Client): The client instance to be used for asynchronous REST interactions.
|
|
193
|
+
"""
|
|
194
|
+
self._client = _client
|
|
195
|
+
|
|
196
|
+
async def create(
|
|
197
|
+
self,
|
|
198
|
+
workflow_name: str,
|
|
199
|
+
cron_name: str,
|
|
200
|
+
expression: str,
|
|
201
|
+
input: dict,
|
|
202
|
+
additional_metadata: dict[str, str],
|
|
203
|
+
) -> CronWorkflows:
|
|
204
|
+
"""
|
|
205
|
+
Asynchronously creates a new workflow cron trigger.
|
|
206
|
+
|
|
207
|
+
Args:
|
|
208
|
+
workflow_name (str): The name of the workflow to trigger.
|
|
209
|
+
cron_name (str): The name of the cron trigger.
|
|
210
|
+
expression (str): The cron expression defining the schedule.
|
|
211
|
+
input (dict): The input data for the cron workflow.
|
|
212
|
+
additional_metadata (dict[str, str]): Additional metadata associated with the cron trigger (e.g. {"key1": "value1", "key2": "value2"}).
|
|
213
|
+
|
|
214
|
+
Returns:
|
|
215
|
+
CronWorkflows: The created cron workflow instance.
|
|
216
|
+
"""
|
|
217
|
+
validated_input = CreateCronTriggerInput(
|
|
218
|
+
expression=expression, input=input, additional_metadata=additional_metadata
|
|
219
|
+
)
|
|
220
|
+
|
|
221
|
+
return await self._client.rest.aio.cron_create(
|
|
222
|
+
workflow_name=workflow_name,
|
|
223
|
+
cron_name=cron_name,
|
|
224
|
+
expression=validated_input.expression,
|
|
225
|
+
input=validated_input.input,
|
|
226
|
+
additional_metadata=validated_input.additional_metadata,
|
|
227
|
+
)
|
|
228
|
+
|
|
229
|
+
async def delete(self, cron_trigger: Union[str, CronWorkflows]) -> None:
|
|
230
|
+
"""
|
|
231
|
+
Asynchronously deletes a workflow cron trigger.
|
|
232
|
+
|
|
233
|
+
Args:
|
|
234
|
+
cron_trigger (Union[str, CronWorkflows]): The cron trigger ID or CronWorkflows instance to delete.
|
|
235
|
+
"""
|
|
236
|
+
id_ = cron_trigger
|
|
237
|
+
if isinstance(cron_trigger, CronWorkflows):
|
|
238
|
+
id_ = cron_trigger.metadata.id
|
|
239
|
+
await self._client.rest.aio.cron_delete(id_)
|
|
240
|
+
|
|
241
|
+
async def list(
|
|
242
|
+
self,
|
|
243
|
+
offset: int | None = None,
|
|
244
|
+
limit: int | None = None,
|
|
245
|
+
workflow_id: str | None = None,
|
|
246
|
+
additional_metadata: list[str] | None = None,
|
|
247
|
+
order_by_field: CronWorkflowsOrderByField | None = None,
|
|
248
|
+
order_by_direction: WorkflowRunOrderByDirection | None = None,
|
|
249
|
+
) -> CronWorkflowsList:
|
|
250
|
+
"""
|
|
251
|
+
Asynchronously retrieves a list of all workflow cron triggers matching the criteria.
|
|
252
|
+
|
|
253
|
+
Args:
|
|
254
|
+
offset (int | None): The offset to start the list from.
|
|
255
|
+
limit (int | None): The maximum number of items to return.
|
|
256
|
+
workflow_id (str | None): The ID of the workflow to filter by.
|
|
257
|
+
additional_metadata (list[str] | None): Filter by additional metadata keys (e.g. ["key1:value1", "key2:value2"]).
|
|
258
|
+
order_by_field (CronWorkflowsOrderByField | None): The field to order the list by.
|
|
259
|
+
order_by_direction (WorkflowRunOrderByDirection | None): The direction to order the list by.
|
|
260
|
+
|
|
261
|
+
Returns:
|
|
262
|
+
CronWorkflowsList: A list of cron workflows.
|
|
263
|
+
"""
|
|
264
|
+
return await self._client.rest.aio.cron_list(
|
|
265
|
+
offset=offset,
|
|
266
|
+
limit=limit,
|
|
267
|
+
workflow_id=workflow_id,
|
|
268
|
+
additional_metadata=additional_metadata,
|
|
269
|
+
order_by_field=order_by_field,
|
|
270
|
+
order_by_direction=order_by_direction,
|
|
271
|
+
)
|
|
272
|
+
|
|
273
|
+
async def get(self, cron_trigger: Union[str, CronWorkflows]) -> CronWorkflows:
|
|
274
|
+
"""
|
|
275
|
+
Asynchronously retrieves a specific workflow cron trigger by ID.
|
|
276
|
+
|
|
277
|
+
Args:
|
|
278
|
+
cron_trigger (Union[str, CronWorkflows]): The cron trigger ID or CronWorkflows instance to retrieve.
|
|
279
|
+
|
|
280
|
+
Returns:
|
|
281
|
+
CronWorkflows: The requested cron workflow instance.
|
|
282
|
+
"""
|
|
283
|
+
id_ = cron_trigger
|
|
284
|
+
if isinstance(cron_trigger, CronWorkflows):
|
|
285
|
+
id_ = cron_trigger.metadata.id
|
|
286
|
+
return await self._client.rest.aio.cron_get(id_)
|