hatchet-sdk 1.6.2__py3-none-any.whl → 1.6.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.
Potentially problematic release.
This version of hatchet-sdk might be problematic. Click here for more details.
- hatchet_sdk/clients/dispatcher/action_listener.py +24 -3
- hatchet_sdk/clients/event_ts.py +18 -7
- hatchet_sdk/clients/events.py +2 -0
- hatchet_sdk/clients/listeners/pooled_listener.py +9 -5
- hatchet_sdk/context/context.py +5 -2
- hatchet_sdk/features/cron.py +58 -55
- hatchet_sdk/features/logs.py +16 -0
- hatchet_sdk/features/metrics.py +48 -0
- hatchet_sdk/features/rate_limits.py +24 -0
- hatchet_sdk/features/runs.py +143 -5
- hatchet_sdk/features/scheduled.py +51 -51
- hatchet_sdk/features/workers.py +40 -0
- hatchet_sdk/features/workflows.py +50 -0
- hatchet_sdk/hatchet.py +81 -108
- hatchet_sdk/opentelemetry/instrumentor.py +19 -21
- hatchet_sdk/runnables/standalone.py +111 -0
- hatchet_sdk/runnables/workflow.py +197 -76
- hatchet_sdk/v0/features/cron.py +3 -3
- hatchet_sdk/v0/features/scheduled.py +1 -1
- hatchet_sdk/v0/hatchet.py +3 -3
- hatchet_sdk/v0/opentelemetry/instrumentor.py +3 -6
- hatchet_sdk/worker/runner/runner.py +37 -43
- hatchet_sdk/worker/worker.py +3 -3
- {hatchet_sdk-1.6.2.dist-info → hatchet_sdk-1.6.4.dist-info}/METADATA +1 -1
- {hatchet_sdk-1.6.2.dist-info → hatchet_sdk-1.6.4.dist-info}/RECORD +27 -27
- {hatchet_sdk-1.6.2.dist-info → hatchet_sdk-1.6.4.dist-info}/entry_points.txt +4 -0
- {hatchet_sdk-1.6.2.dist-info → hatchet_sdk-1.6.4.dist-info}/WHEEL +0 -0
hatchet_sdk/hatchet.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import asyncio
|
|
2
2
|
import logging
|
|
3
|
-
from typing import Any, Callable, Type, cast, overload
|
|
3
|
+
from typing import Any, Callable, Type, Union, cast, overload
|
|
4
4
|
|
|
5
5
|
from hatchet_sdk import Context, DurableContext
|
|
6
6
|
from hatchet_sdk.client import Client
|
|
@@ -41,15 +41,7 @@ class Hatchet:
|
|
|
41
41
|
Main client for interacting with the Hatchet SDK.
|
|
42
42
|
|
|
43
43
|
This class provides access to various client interfaces and utility methods
|
|
44
|
-
for working with Hatchet workers, workflows, and
|
|
45
|
-
|
|
46
|
-
Attributes:
|
|
47
|
-
cron (CronClient): Interface for cron trigger operations.
|
|
48
|
-
|
|
49
|
-
admin (AdminClient): Interface for administrative operations.
|
|
50
|
-
dispatcher (DispatcherClient): Interface for dispatching operations.
|
|
51
|
-
event (EventClient): Interface for event-related operations.
|
|
52
|
-
rest (RestApi): Interface for REST API operations.
|
|
44
|
+
for working with Hatchet workers, workflows, tasks, and our various feature clients.
|
|
53
45
|
"""
|
|
54
46
|
|
|
55
47
|
def __init__(
|
|
@@ -58,19 +50,6 @@ class Hatchet:
|
|
|
58
50
|
client: Client | None = None,
|
|
59
51
|
config: ClientConfig | None = None,
|
|
60
52
|
):
|
|
61
|
-
"""
|
|
62
|
-
Initialize a new Hatchet instance.
|
|
63
|
-
|
|
64
|
-
:param debug: Enable debug logging. Default: `False`
|
|
65
|
-
:type debug: bool
|
|
66
|
-
|
|
67
|
-
:param client: A pre-configured `Client` instance. Default: `None`.
|
|
68
|
-
:type client: Client | None
|
|
69
|
-
|
|
70
|
-
:param config: Configuration for creating a new Client. Defaults to ClientConfig()
|
|
71
|
-
:type config: ClientConfig
|
|
72
|
-
"""
|
|
73
|
-
|
|
74
53
|
if debug:
|
|
75
54
|
logger.setLevel(logging.DEBUG)
|
|
76
55
|
|
|
@@ -80,34 +59,60 @@ class Hatchet:
|
|
|
80
59
|
|
|
81
60
|
@property
|
|
82
61
|
def cron(self) -> CronClient:
|
|
62
|
+
"""
|
|
63
|
+
The cron client is a client for managing cron workflows within Hatchet.
|
|
64
|
+
"""
|
|
83
65
|
return self._client.cron
|
|
84
66
|
|
|
85
67
|
@property
|
|
86
68
|
def logs(self) -> LogsClient:
|
|
69
|
+
"""
|
|
70
|
+
The logs client is a client for interacting with Hatchet's logs API.
|
|
71
|
+
"""
|
|
87
72
|
return self._client.logs
|
|
88
73
|
|
|
89
74
|
@property
|
|
90
75
|
def metrics(self) -> MetricsClient:
|
|
76
|
+
"""
|
|
77
|
+
The metrics client is a client for reading metrics out of Hatchet's metrics API.
|
|
78
|
+
"""
|
|
91
79
|
return self._client.metrics
|
|
92
80
|
|
|
93
81
|
@property
|
|
94
82
|
def rate_limits(self) -> RateLimitsClient:
|
|
83
|
+
"""
|
|
84
|
+
The rate limits client is a wrapper for Hatchet's gRPC API that makes it easier to work with rate limits in Hatchet.
|
|
85
|
+
"""
|
|
95
86
|
return self._client.rate_limits
|
|
96
87
|
|
|
97
88
|
@property
|
|
98
89
|
def runs(self) -> RunsClient:
|
|
90
|
+
"""
|
|
91
|
+
The runs client is a client for interacting with task and workflow runs within Hatchet.
|
|
92
|
+
"""
|
|
99
93
|
return self._client.runs
|
|
100
94
|
|
|
101
95
|
@property
|
|
102
96
|
def scheduled(self) -> ScheduledClient:
|
|
97
|
+
"""
|
|
98
|
+
The scheduled client is a client for managing scheduled workflows within Hatchet.
|
|
99
|
+
"""
|
|
103
100
|
return self._client.scheduled
|
|
104
101
|
|
|
105
102
|
@property
|
|
106
103
|
def workers(self) -> WorkersClient:
|
|
104
|
+
"""
|
|
105
|
+
The workers client is a client for managing workers programmatically within Hatchet.
|
|
106
|
+
"""
|
|
107
107
|
return self._client.workers
|
|
108
108
|
|
|
109
109
|
@property
|
|
110
110
|
def workflows(self) -> WorkflowsClient:
|
|
111
|
+
"""
|
|
112
|
+
The workflows client is a client for managing workflows programmatically within Hatchet.
|
|
113
|
+
|
|
114
|
+
Note that workflows are the declaration, _not_ the individual runs. If you're looking for runs, use the `RunsClient` instead.
|
|
115
|
+
"""
|
|
111
116
|
return self._client.workflows
|
|
112
117
|
|
|
113
118
|
@property
|
|
@@ -116,6 +121,9 @@ class Hatchet:
|
|
|
116
121
|
|
|
117
122
|
@property
|
|
118
123
|
def event(self) -> EventClient:
|
|
124
|
+
"""
|
|
125
|
+
The event client, which you can use to push events to Hatchet.
|
|
126
|
+
"""
|
|
119
127
|
return self._client.event
|
|
120
128
|
|
|
121
129
|
@property
|
|
@@ -128,14 +136,24 @@ class Hatchet:
|
|
|
128
136
|
|
|
129
137
|
@property
|
|
130
138
|
def tenant_id(self) -> str:
|
|
139
|
+
"""
|
|
140
|
+
The tenant id you're operating in.
|
|
141
|
+
"""
|
|
131
142
|
return self._client.config.tenant_id
|
|
132
143
|
|
|
144
|
+
@property
|
|
145
|
+
def namespace(self) -> str:
|
|
146
|
+
"""
|
|
147
|
+
The current namespace you're interacting with.
|
|
148
|
+
"""
|
|
149
|
+
return self._client.config.namespace
|
|
150
|
+
|
|
133
151
|
def worker(
|
|
134
152
|
self,
|
|
135
153
|
name: str,
|
|
136
154
|
slots: int = 100,
|
|
137
155
|
durable_slots: int = 1_000,
|
|
138
|
-
labels: dict[str, str
|
|
156
|
+
labels: dict[str, Union[str, int]] = {},
|
|
139
157
|
workflows: list[BaseWorkflow[Any]] = [],
|
|
140
158
|
lifespan: LifespanFn | None = None,
|
|
141
159
|
) -> Worker:
|
|
@@ -143,20 +161,18 @@ class Hatchet:
|
|
|
143
161
|
Create a Hatchet worker on which to run workflows.
|
|
144
162
|
|
|
145
163
|
:param name: The name of the worker.
|
|
146
|
-
:type name: str
|
|
147
164
|
|
|
148
|
-
:param slots: The number of workflow slots on the worker. In other words, the number of concurrent tasks the worker can run at any point in time
|
|
149
|
-
|
|
165
|
+
:param slots: The number of workflow slots on the worker. In other words, the number of concurrent tasks the worker can run at any point in time
|
|
166
|
+
|
|
167
|
+
:param durable_slots: The number of durable workflow slots on the worker. In other words, the number of concurrent tasks the worker can run at any point in time that are durable.
|
|
150
168
|
|
|
151
|
-
:param labels: A dictionary of labels to assign to the worker. For more details, view examples on affinity and worker labels.
|
|
152
|
-
:type labels: dict[str, str | int]
|
|
169
|
+
:param labels: A dictionary of labels to assign to the worker. For more details, view examples on affinity and worker labels.
|
|
153
170
|
|
|
154
|
-
:param workflows: A list of workflows to register on the worker, as a shorthand for calling `register_workflow` on each or `register_workflows` on all of them.
|
|
155
|
-
:type workflows: list[Workflow]
|
|
171
|
+
:param workflows: A list of workflows to register on the worker, as a shorthand for calling `register_workflow` on each or `register_workflows` on all of them.
|
|
156
172
|
|
|
173
|
+
:param lifespan: A lifespan function to run on the worker. This function will be called when the worker is started, and can be used to perform any setup or teardown tasks.
|
|
157
174
|
|
|
158
175
|
:returns: The created `Worker` object, which exposes an instance method `start` which can be called to start the worker.
|
|
159
|
-
:rtype: Worker
|
|
160
176
|
"""
|
|
161
177
|
|
|
162
178
|
try:
|
|
@@ -226,37 +242,26 @@ class Hatchet:
|
|
|
226
242
|
Define a Hatchet workflow, which can then declare `task`s and be `run`, `schedule`d, and so on.
|
|
227
243
|
|
|
228
244
|
:param name: The name of the workflow.
|
|
229
|
-
:type name: str
|
|
230
245
|
|
|
231
|
-
:param description: A description for the workflow
|
|
232
|
-
:type description: str | None
|
|
233
|
-
|
|
234
|
-
:param version: A version for the workflow. Default: None
|
|
235
|
-
:type version: str | None
|
|
246
|
+
:param description: A description for the workflow
|
|
236
247
|
|
|
237
248
|
:param input_validator: A Pydantic model to use as a validator for the `input` to the tasks in the workflow. If no validator is provided, defaults to an `EmptyModel` under the hood. The `EmptyModel` is a Pydantic model with no fields specified, and with the `extra` config option set to `"allow"`.
|
|
238
|
-
:type input_validator: Type[BaseModel]
|
|
239
249
|
|
|
240
|
-
:param on_events: A list of event triggers for the workflow - events which cause the workflow to be run.
|
|
241
|
-
|
|
250
|
+
:param on_events: A list of event triggers for the workflow - events which cause the workflow to be run.
|
|
251
|
+
|
|
252
|
+
:param on_crons: A list of cron triggers for the workflow.
|
|
242
253
|
|
|
243
|
-
:param
|
|
244
|
-
:type on_crons: list[str]
|
|
254
|
+
:param version: A version for the workflow
|
|
245
255
|
|
|
246
|
-
:param sticky: A sticky strategy for the workflow
|
|
247
|
-
:type sticky: StickyStategy
|
|
256
|
+
:param sticky: A sticky strategy for the workflow
|
|
248
257
|
|
|
249
|
-
:param default_priority: The priority of the workflow. Higher values will cause this workflow to have priority in scheduling over other, lower priority ones.
|
|
250
|
-
:type default_priority: int
|
|
258
|
+
:param default_priority: The priority of the workflow. Higher values will cause this workflow to have priority in scheduling over other, lower priority ones.
|
|
251
259
|
|
|
252
260
|
:param concurrency: A concurrency object controlling the concurrency settings for this workflow.
|
|
253
|
-
:type concurrency: ConcurrencyExpression | None
|
|
254
261
|
|
|
255
262
|
:param task_defaults: A `TaskDefaults` object controlling the default task settings for this workflow.
|
|
256
|
-
:type task_defaults: TaskDefaults
|
|
257
263
|
|
|
258
264
|
:returns: The created `Workflow` object, which can be used to declare tasks, run the workflow, and so on.
|
|
259
|
-
:rtype: Workflow
|
|
260
265
|
"""
|
|
261
266
|
|
|
262
267
|
return Workflow[TWorkflowInput](
|
|
@@ -351,55 +356,38 @@ class Hatchet:
|
|
|
351
356
|
A decorator to transform a function into a standalone Hatchet task that runs as part of a workflow.
|
|
352
357
|
|
|
353
358
|
:param name: The name of the task. If not specified, defaults to the name of the function being wrapped by the `task` decorator.
|
|
354
|
-
:type name: str
|
|
355
359
|
|
|
356
|
-
:param description: An optional description for the task.
|
|
357
|
-
:type description: str | None
|
|
360
|
+
:param description: An optional description for the task.
|
|
358
361
|
|
|
359
362
|
:param input_validator: A Pydantic model to use as a validator for the input to the task. If no validator is provided, defaults to an `EmptyModel`.
|
|
360
|
-
:type input_validator: Type[BaseModel]
|
|
361
363
|
|
|
362
|
-
:param on_events: A list of event triggers for the task - events which cause the task to be run.
|
|
363
|
-
:type on_events: list[str]
|
|
364
|
+
:param on_events: A list of event triggers for the task - events which cause the task to be run.
|
|
364
365
|
|
|
365
|
-
:param on_crons: A list of cron triggers for the task.
|
|
366
|
-
:type on_crons: list[str]
|
|
366
|
+
:param on_crons: A list of cron triggers for the task.
|
|
367
367
|
|
|
368
|
-
:param version: A version for the task.
|
|
369
|
-
:type version: str | None
|
|
368
|
+
:param version: A version for the task.
|
|
370
369
|
|
|
371
|
-
:param sticky: A sticky strategy for the task.
|
|
372
|
-
:type sticky: StickyStrategy | None
|
|
370
|
+
:param sticky: A sticky strategy for the task.
|
|
373
371
|
|
|
374
|
-
:param default_priority: The priority of the task. Higher values will cause this task to have priority in scheduling.
|
|
375
|
-
:type default_priority: int
|
|
372
|
+
:param default_priority: The priority of the task. Higher values will cause this task to have priority in scheduling.
|
|
376
373
|
|
|
377
374
|
:param concurrency: A concurrency object controlling the concurrency settings for this task.
|
|
378
|
-
:type concurrency: ConcurrencyExpression | None
|
|
379
375
|
|
|
380
|
-
:param schedule_timeout: The maximum time allowed for scheduling the task.
|
|
381
|
-
:type schedule_timeout: Duration
|
|
376
|
+
:param schedule_timeout: The maximum time allowed for scheduling the task.
|
|
382
377
|
|
|
383
|
-
:param execution_timeout: The maximum time allowed for executing the task.
|
|
384
|
-
:type execution_timeout: Duration
|
|
378
|
+
:param execution_timeout: The maximum time allowed for executing the task.
|
|
385
379
|
|
|
386
|
-
:param retries: The number of times to retry the task before failing.
|
|
387
|
-
:type retries: int
|
|
380
|
+
:param retries: The number of times to retry the task before failing.
|
|
388
381
|
|
|
389
|
-
:param rate_limits: A list of rate limit configurations for the task.
|
|
390
|
-
:type rate_limits: list[RateLimit]
|
|
382
|
+
:param rate_limits: A list of rate limit configurations for the task.
|
|
391
383
|
|
|
392
384
|
:param desired_worker_labels: A dictionary of desired worker labels that determine to which worker the task should be assigned.
|
|
393
|
-
:type desired_worker_labels: dict[str, DesiredWorkerLabel]
|
|
394
385
|
|
|
395
|
-
:param backoff_factor: The backoff factor for controlling exponential backoff in retries.
|
|
396
|
-
:type backoff_factor: float | None
|
|
386
|
+
:param backoff_factor: The backoff factor for controlling exponential backoff in retries.
|
|
397
387
|
|
|
398
|
-
:param backoff_max_seconds: The maximum number of seconds to allow retries with exponential backoff to continue.
|
|
399
|
-
:type backoff_max_seconds: int | None
|
|
388
|
+
:param backoff_max_seconds: The maximum number of seconds to allow retries with exponential backoff to continue.
|
|
400
389
|
|
|
401
390
|
:returns: A decorator which creates a `Standalone` task object.
|
|
402
|
-
:rtype: Callable[[Callable[[TWorkflowInput, Context], R]], Standalone[TWorkflowInput, R]]
|
|
403
391
|
"""
|
|
404
392
|
|
|
405
393
|
workflow = Workflow[TWorkflowInput](
|
|
@@ -411,6 +399,7 @@ class Hatchet:
|
|
|
411
399
|
on_crons=on_crons,
|
|
412
400
|
sticky=sticky,
|
|
413
401
|
concurrency=concurrency,
|
|
402
|
+
default_priority=default_priority,
|
|
414
403
|
input_validator=input_validator
|
|
415
404
|
or cast(Type[TWorkflowInput], EmptyModel),
|
|
416
405
|
),
|
|
@@ -527,55 +516,38 @@ class Hatchet:
|
|
|
527
516
|
A decorator to transform a function into a standalone Hatchet _durable_ task that runs as part of a workflow.
|
|
528
517
|
|
|
529
518
|
:param name: The name of the task. If not specified, defaults to the name of the function being wrapped by the `task` decorator.
|
|
530
|
-
:type name: str
|
|
531
519
|
|
|
532
|
-
:param description: An optional description for the task.
|
|
533
|
-
:type description: str | None
|
|
520
|
+
:param description: An optional description for the task.
|
|
534
521
|
|
|
535
522
|
:param input_validator: A Pydantic model to use as a validator for the input to the task. If no validator is provided, defaults to an `EmptyModel`.
|
|
536
|
-
:type input_validator: Type[BaseModel]
|
|
537
523
|
|
|
538
|
-
:param on_events: A list of event triggers for the task - events which cause the task to be run.
|
|
539
|
-
:type on_events: list[str]
|
|
524
|
+
:param on_events: A list of event triggers for the task - events which cause the task to be run.
|
|
540
525
|
|
|
541
|
-
:param on_crons: A list of cron triggers for the task.
|
|
542
|
-
:type on_crons: list[str]
|
|
526
|
+
:param on_crons: A list of cron triggers for the task.
|
|
543
527
|
|
|
544
|
-
:param version: A version for the task.
|
|
545
|
-
:type version: str | None
|
|
528
|
+
:param version: A version for the task.
|
|
546
529
|
|
|
547
|
-
:param sticky: A sticky strategy for the task.
|
|
548
|
-
:type sticky: StickyStrategy | None
|
|
530
|
+
:param sticky: A sticky strategy for the task.
|
|
549
531
|
|
|
550
|
-
:param default_priority: The priority of the task. Higher values will cause this task to have priority in scheduling.
|
|
551
|
-
:type default_priority: int
|
|
532
|
+
:param default_priority: The priority of the task. Higher values will cause this task to have priority in scheduling.
|
|
552
533
|
|
|
553
534
|
:param concurrency: A concurrency object controlling the concurrency settings for this task.
|
|
554
|
-
:type concurrency: ConcurrencyExpression | None
|
|
555
535
|
|
|
556
|
-
:param schedule_timeout: The maximum time allowed for scheduling the task.
|
|
557
|
-
:type schedule_timeout: Duration
|
|
536
|
+
:param schedule_timeout: The maximum time allowed for scheduling the task.
|
|
558
537
|
|
|
559
|
-
:param execution_timeout: The maximum time allowed for executing the task.
|
|
560
|
-
:type execution_timeout: Duration
|
|
538
|
+
:param execution_timeout: The maximum time allowed for executing the task.
|
|
561
539
|
|
|
562
|
-
:param retries: The number of times to retry the task before failing.
|
|
563
|
-
:type retries: int
|
|
540
|
+
:param retries: The number of times to retry the task before failing.
|
|
564
541
|
|
|
565
|
-
:param rate_limits: A list of rate limit configurations for the task.
|
|
566
|
-
:type rate_limits: list[RateLimit]
|
|
542
|
+
:param rate_limits: A list of rate limit configurations for the task.
|
|
567
543
|
|
|
568
544
|
:param desired_worker_labels: A dictionary of desired worker labels that determine to which worker the task should be assigned.
|
|
569
|
-
:type desired_worker_labels: dict[str, DesiredWorkerLabel]
|
|
570
545
|
|
|
571
|
-
:param backoff_factor: The backoff factor for controlling exponential backoff in retries.
|
|
572
|
-
:type backoff_factor: float | None
|
|
546
|
+
:param backoff_factor: The backoff factor for controlling exponential backoff in retries.
|
|
573
547
|
|
|
574
|
-
:param backoff_max_seconds: The maximum number of seconds to allow retries with exponential backoff to continue.
|
|
575
|
-
:type backoff_max_seconds: int | None
|
|
548
|
+
:param backoff_max_seconds: The maximum number of seconds to allow retries with exponential backoff to continue.
|
|
576
549
|
|
|
577
550
|
:returns: A decorator which creates a `Standalone` task object.
|
|
578
|
-
:rtype: Callable[[Callable[[TWorkflowInput, Context], R]], Standalone[TWorkflowInput, R]]
|
|
579
551
|
"""
|
|
580
552
|
|
|
581
553
|
workflow = Workflow[TWorkflowInput](
|
|
@@ -589,6 +561,7 @@ class Hatchet:
|
|
|
589
561
|
concurrency=concurrency,
|
|
590
562
|
input_validator=input_validator
|
|
591
563
|
or cast(Type[TWorkflowInput], EmptyModel),
|
|
564
|
+
default_priority=default_priority,
|
|
592
565
|
),
|
|
593
566
|
self,
|
|
594
567
|
)
|
|
@@ -59,7 +59,6 @@ def create_traceparent() -> str | None:
|
|
|
59
59
|
:returns: A W3C-formatted traceparent header value if successful, None if the context
|
|
60
60
|
injection fails or no active span exists.\n
|
|
61
61
|
Example: `00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01`
|
|
62
|
-
:rtype: str | None:
|
|
63
62
|
"""
|
|
64
63
|
|
|
65
64
|
carrier: dict[str, str] = {}
|
|
@@ -79,10 +78,9 @@ def parse_carrier_from_metadata(
|
|
|
79
78
|
|
|
80
79
|
:param metadata: A dictionary containing metadata key-value pairs,
|
|
81
80
|
potentially including the `traceparent` header. Can be None.
|
|
82
|
-
|
|
81
|
+
|
|
83
82
|
:returns: The extracted OpenTelemetry Context object if a valid `traceparent`
|
|
84
83
|
is found in the metadata, otherwise None.
|
|
85
|
-
:rtype: Context | None
|
|
86
84
|
|
|
87
85
|
:Example:
|
|
88
86
|
|
|
@@ -112,13 +110,12 @@ def inject_traceparent_into_metadata(
|
|
|
112
110
|
`OTEL_TRACEPARENT_KEY`. If no `traceparent` is provided, it attempts to create one.
|
|
113
111
|
|
|
114
112
|
:param metadata: The metadata dictionary to inject the `traceparent` into.
|
|
115
|
-
|
|
113
|
+
|
|
116
114
|
:param traceparent: The `traceparent` string to inject. If None, attempts to use
|
|
117
115
|
the current span.
|
|
118
|
-
|
|
116
|
+
|
|
119
117
|
:returns: A new metadata dictionary containing the original metadata plus
|
|
120
118
|
the injected `traceparent`, if one was available or could be created.
|
|
121
|
-
:rtype: dict[str, str]
|
|
122
119
|
|
|
123
120
|
:Example:
|
|
124
121
|
|
|
@@ -141,22 +138,23 @@ def inject_traceparent_into_metadata(
|
|
|
141
138
|
|
|
142
139
|
|
|
143
140
|
class HatchetInstrumentor(BaseInstrumentor): # type: ignore[misc]
|
|
141
|
+
"""
|
|
142
|
+
Hatchet OpenTelemetry instrumentor.
|
|
143
|
+
|
|
144
|
+
The instrumentor provides an OpenTelemetry integration for Hatchet by setting up
|
|
145
|
+
tracing and metrics collection.
|
|
146
|
+
|
|
147
|
+
:param tracer_provider: TracerProvider | None: The OpenTelemetry TracerProvider to use.
|
|
148
|
+
If not provided, the global tracer provider will be used.
|
|
149
|
+
:param meter_provider: MeterProvider | None: The OpenTelemetry MeterProvider to use.
|
|
150
|
+
If not provided, a no-op meter provider will be used.
|
|
151
|
+
"""
|
|
152
|
+
|
|
144
153
|
def __init__(
|
|
145
154
|
self,
|
|
146
155
|
tracer_provider: TracerProvider | None = None,
|
|
147
156
|
meter_provider: MeterProvider | None = None,
|
|
148
157
|
):
|
|
149
|
-
"""
|
|
150
|
-
Hatchet OpenTelemetry instrumentor.
|
|
151
|
-
|
|
152
|
-
The instrumentor provides an OpenTelemetry integration for Hatchet by setting up
|
|
153
|
-
tracing and metrics collection.
|
|
154
|
-
|
|
155
|
-
:param tracer_provider: TracerProvider | None: The OpenTelemetry TracerProvider to use.
|
|
156
|
-
If not provided, the global tracer provider will be used.
|
|
157
|
-
:param meter_provider: MeterProvider | None: The OpenTelemetry MeterProvider to use.
|
|
158
|
-
If not provided, a no-op meter provider will be used.
|
|
159
|
-
"""
|
|
160
158
|
|
|
161
159
|
self.tracer_provider = tracer_provider or get_tracer_provider()
|
|
162
160
|
self.meter_provider = meter_provider or NoOpMeterProvider()
|
|
@@ -269,17 +267,17 @@ class HatchetInstrumentor(BaseInstrumentor): # type: ignore[misc]
|
|
|
269
267
|
## IMPORTANT: Keep these types in sync with the wrapped method's signature
|
|
270
268
|
async def _wrap_handle_cancel_action(
|
|
271
269
|
self,
|
|
272
|
-
wrapped: Callable[[
|
|
270
|
+
wrapped: Callable[[Action], Coroutine[None, None, Exception | None]],
|
|
273
271
|
instance: Runner,
|
|
274
|
-
args: tuple[
|
|
272
|
+
args: tuple[Action],
|
|
275
273
|
kwargs: Any,
|
|
276
274
|
) -> Exception | None:
|
|
277
|
-
|
|
275
|
+
action = args[0]
|
|
278
276
|
|
|
279
277
|
with self._tracer.start_as_current_span(
|
|
280
278
|
"hatchet.cancel_step_run",
|
|
281
279
|
attributes={
|
|
282
|
-
"hatchet.step_run_id": step_run_id,
|
|
280
|
+
"hatchet.step_run_id": action.step_run_id,
|
|
283
281
|
},
|
|
284
282
|
):
|
|
285
283
|
return await wrapped(*args, **kwargs)
|
|
@@ -75,6 +75,15 @@ class Standalone(BaseWorkflow[TWorkflowInput], Generic[TWorkflowInput, R]):
|
|
|
75
75
|
input: TWorkflowInput = cast(TWorkflowInput, EmptyModel()),
|
|
76
76
|
options: TriggerWorkflowOptions = TriggerWorkflowOptions(),
|
|
77
77
|
) -> R:
|
|
78
|
+
"""
|
|
79
|
+
Synchronously trigger a workflow run without waiting for it to complete.
|
|
80
|
+
This method is useful for starting a workflow run and immediately returning a reference to the run without blocking while the workflow runs.
|
|
81
|
+
|
|
82
|
+
:param input: The input data for the workflow.
|
|
83
|
+
:param options: Additional options for workflow execution.
|
|
84
|
+
|
|
85
|
+
:returns: A `WorkflowRunRef` object representing the reference to the workflow run.
|
|
86
|
+
"""
|
|
78
87
|
return self._extract_result(self._workflow.run(input, options))
|
|
79
88
|
|
|
80
89
|
async def aio_run(
|
|
@@ -82,6 +91,16 @@ class Standalone(BaseWorkflow[TWorkflowInput], Generic[TWorkflowInput, R]):
|
|
|
82
91
|
input: TWorkflowInput = cast(TWorkflowInput, EmptyModel()),
|
|
83
92
|
options: TriggerWorkflowOptions = TriggerWorkflowOptions(),
|
|
84
93
|
) -> R:
|
|
94
|
+
"""
|
|
95
|
+
Run the workflow asynchronously and wait for it to complete.
|
|
96
|
+
|
|
97
|
+
This method triggers a workflow run, blocks until completion, and returns the final result.
|
|
98
|
+
|
|
99
|
+
:param input: The input data for the workflow, must match the workflow's input type.
|
|
100
|
+
:param options: Additional options for workflow execution like metadata and parent workflow ID.
|
|
101
|
+
|
|
102
|
+
:returns: The result of the workflow execution as a dictionary.
|
|
103
|
+
"""
|
|
85
104
|
result = await self._workflow.aio_run(input, options)
|
|
86
105
|
return self._extract_result(result)
|
|
87
106
|
|
|
@@ -90,6 +109,16 @@ class Standalone(BaseWorkflow[TWorkflowInput], Generic[TWorkflowInput, R]):
|
|
|
90
109
|
input: TWorkflowInput = cast(TWorkflowInput, EmptyModel()),
|
|
91
110
|
options: TriggerWorkflowOptions = TriggerWorkflowOptions(),
|
|
92
111
|
) -> TaskRunRef[TWorkflowInput, R]:
|
|
112
|
+
"""
|
|
113
|
+
Run the workflow synchronously and wait for it to complete.
|
|
114
|
+
|
|
115
|
+
This method triggers a workflow run, blocks until completion, and returns the final result.
|
|
116
|
+
|
|
117
|
+
:param input: The input data for the workflow, must match the workflow's input type.
|
|
118
|
+
:param options: Additional options for workflow execution like metadata and parent workflow ID.
|
|
119
|
+
|
|
120
|
+
:returns: The result of the workflow execution as a dictionary.
|
|
121
|
+
"""
|
|
93
122
|
ref = self._workflow.run_no_wait(input, options)
|
|
94
123
|
|
|
95
124
|
return TaskRunRef[TWorkflowInput, R](self, ref)
|
|
@@ -99,17 +128,40 @@ class Standalone(BaseWorkflow[TWorkflowInput], Generic[TWorkflowInput, R]):
|
|
|
99
128
|
input: TWorkflowInput = cast(TWorkflowInput, EmptyModel()),
|
|
100
129
|
options: TriggerWorkflowOptions = TriggerWorkflowOptions(),
|
|
101
130
|
) -> TaskRunRef[TWorkflowInput, R]:
|
|
131
|
+
"""
|
|
132
|
+
Asynchronously trigger a workflow run without waiting for it to complete.
|
|
133
|
+
This method is useful for starting a workflow run and immediately returning a reference to the run without blocking while the workflow runs.
|
|
134
|
+
|
|
135
|
+
:param input: The input data for the workflow.
|
|
136
|
+
:param options: Additional options for workflow execution.
|
|
137
|
+
|
|
138
|
+
:returns: A `WorkflowRunRef` object representing the reference to the workflow run.
|
|
139
|
+
"""
|
|
102
140
|
ref = await self._workflow.aio_run_no_wait(input, options)
|
|
103
141
|
|
|
104
142
|
return TaskRunRef[TWorkflowInput, R](self, ref)
|
|
105
143
|
|
|
106
144
|
def run_many(self, workflows: list[WorkflowRunTriggerConfig]) -> list[R]:
|
|
145
|
+
"""
|
|
146
|
+
Run a workflow in bulk and wait for all runs to complete.
|
|
147
|
+
This method triggers multiple workflow runs, blocks until all of them complete, and returns the final results.
|
|
148
|
+
|
|
149
|
+
:param workflows: A list of `WorkflowRunTriggerConfig` objects, each representing a workflow run to be triggered.
|
|
150
|
+
:returns: A list of results for each workflow run.
|
|
151
|
+
"""
|
|
107
152
|
return [
|
|
108
153
|
self._extract_result(result)
|
|
109
154
|
for result in self._workflow.run_many(workflows)
|
|
110
155
|
]
|
|
111
156
|
|
|
112
157
|
async def aio_run_many(self, workflows: list[WorkflowRunTriggerConfig]) -> list[R]:
|
|
158
|
+
"""
|
|
159
|
+
Run a workflow in bulk and wait for all runs to complete.
|
|
160
|
+
This method triggers multiple workflow runs, blocks until all of them complete, and returns the final results.
|
|
161
|
+
|
|
162
|
+
:param workflows: A list of `WorkflowRunTriggerConfig` objects, each representing a workflow run to be triggered.
|
|
163
|
+
:returns: A list of results for each workflow run.
|
|
164
|
+
"""
|
|
113
165
|
return [
|
|
114
166
|
self._extract_result(result)
|
|
115
167
|
for result in await self._workflow.aio_run_many(workflows)
|
|
@@ -118,6 +170,14 @@ class Standalone(BaseWorkflow[TWorkflowInput], Generic[TWorkflowInput, R]):
|
|
|
118
170
|
def run_many_no_wait(
|
|
119
171
|
self, workflows: list[WorkflowRunTriggerConfig]
|
|
120
172
|
) -> list[TaskRunRef[TWorkflowInput, R]]:
|
|
173
|
+
"""
|
|
174
|
+
Run a workflow in bulk without waiting for all runs to complete.
|
|
175
|
+
|
|
176
|
+
This method triggers multiple workflow runs and immediately returns a list of references to the runs without blocking while the workflows run.
|
|
177
|
+
|
|
178
|
+
:param workflows: A list of `WorkflowRunTriggerConfig` objects, each representing a workflow run to be triggered.
|
|
179
|
+
:returns: A list of `WorkflowRunRef` objects, each representing a reference to a workflow run.
|
|
180
|
+
"""
|
|
121
181
|
refs = self._workflow.run_many_no_wait(workflows)
|
|
122
182
|
|
|
123
183
|
return [TaskRunRef[TWorkflowInput, R](self, ref) for ref in refs]
|
|
@@ -125,6 +185,15 @@ class Standalone(BaseWorkflow[TWorkflowInput], Generic[TWorkflowInput, R]):
|
|
|
125
185
|
async def aio_run_many_no_wait(
|
|
126
186
|
self, workflows: list[WorkflowRunTriggerConfig]
|
|
127
187
|
) -> list[TaskRunRef[TWorkflowInput, R]]:
|
|
188
|
+
"""
|
|
189
|
+
Run a workflow in bulk without waiting for all runs to complete.
|
|
190
|
+
|
|
191
|
+
This method triggers multiple workflow runs and immediately returns a list of references to the runs without blocking while the workflows run.
|
|
192
|
+
|
|
193
|
+
:param workflows: A list of `WorkflowRunTriggerConfig` objects, each representing a workflow run to be triggered.
|
|
194
|
+
|
|
195
|
+
:returns: A list of `WorkflowRunRef` objects, each representing a reference to a workflow run.
|
|
196
|
+
"""
|
|
128
197
|
refs = await self._workflow.aio_run_many_no_wait(workflows)
|
|
129
198
|
|
|
130
199
|
return [TaskRunRef[TWorkflowInput, R](self, ref) for ref in refs]
|
|
@@ -135,6 +204,14 @@ class Standalone(BaseWorkflow[TWorkflowInput], Generic[TWorkflowInput, R]):
|
|
|
135
204
|
input: TWorkflowInput = cast(TWorkflowInput, EmptyModel()),
|
|
136
205
|
options: ScheduleTriggerWorkflowOptions = ScheduleTriggerWorkflowOptions(),
|
|
137
206
|
) -> WorkflowVersion:
|
|
207
|
+
"""
|
|
208
|
+
Schedule a workflow to run at a specific time.
|
|
209
|
+
|
|
210
|
+
:param run_at: The time at which to schedule the workflow.
|
|
211
|
+
:param input: The input data for the workflow.
|
|
212
|
+
:param options: Additional options for workflow execution.
|
|
213
|
+
:returns: A `WorkflowVersion` object representing the scheduled workflow.
|
|
214
|
+
"""
|
|
138
215
|
return self._workflow.schedule(
|
|
139
216
|
run_at=run_at,
|
|
140
217
|
input=input,
|
|
@@ -147,6 +224,14 @@ class Standalone(BaseWorkflow[TWorkflowInput], Generic[TWorkflowInput, R]):
|
|
|
147
224
|
input: TWorkflowInput = cast(TWorkflowInput, EmptyModel()),
|
|
148
225
|
options: ScheduleTriggerWorkflowOptions = ScheduleTriggerWorkflowOptions(),
|
|
149
226
|
) -> WorkflowVersion:
|
|
227
|
+
"""
|
|
228
|
+
Schedule a workflow to run at a specific time.
|
|
229
|
+
|
|
230
|
+
:param run_at: The time at which to schedule the workflow.
|
|
231
|
+
:param input: The input data for the workflow.
|
|
232
|
+
:param options: Additional options for workflow execution.
|
|
233
|
+
:returns: A `WorkflowVersion` object representing the scheduled workflow.
|
|
234
|
+
"""
|
|
150
235
|
return await self._workflow.aio_schedule(
|
|
151
236
|
run_at=run_at,
|
|
152
237
|
input=input,
|
|
@@ -159,12 +244,25 @@ class Standalone(BaseWorkflow[TWorkflowInput], Generic[TWorkflowInput, R]):
|
|
|
159
244
|
expression: str,
|
|
160
245
|
input: TWorkflowInput = cast(TWorkflowInput, EmptyModel()),
|
|
161
246
|
additional_metadata: JSONSerializableMapping = {},
|
|
247
|
+
priority: int | None = None,
|
|
162
248
|
) -> CronWorkflows:
|
|
249
|
+
"""
|
|
250
|
+
Create a cron job for the workflow.
|
|
251
|
+
|
|
252
|
+
:param cron_name: The name of the cron job.
|
|
253
|
+
:param expression: The cron expression that defines the schedule for the cron job.
|
|
254
|
+
:param input: The input data for the workflow.
|
|
255
|
+
:param additional_metadata: Additional metadata for the cron job.
|
|
256
|
+
:param priority: The priority of the cron job. Must be between 1 and 3, inclusive.
|
|
257
|
+
|
|
258
|
+
:returns: A `CronWorkflows` object representing the created cron job.
|
|
259
|
+
"""
|
|
163
260
|
return self._workflow.create_cron(
|
|
164
261
|
cron_name=cron_name,
|
|
165
262
|
expression=expression,
|
|
166
263
|
input=input,
|
|
167
264
|
additional_metadata=additional_metadata,
|
|
265
|
+
priority=priority,
|
|
168
266
|
)
|
|
169
267
|
|
|
170
268
|
async def aio_create_cron(
|
|
@@ -173,12 +271,25 @@ class Standalone(BaseWorkflow[TWorkflowInput], Generic[TWorkflowInput, R]):
|
|
|
173
271
|
expression: str,
|
|
174
272
|
input: TWorkflowInput = cast(TWorkflowInput, EmptyModel()),
|
|
175
273
|
additional_metadata: JSONSerializableMapping = {},
|
|
274
|
+
priority: int | None = None,
|
|
176
275
|
) -> CronWorkflows:
|
|
276
|
+
"""
|
|
277
|
+
Create a cron job for the workflow.
|
|
278
|
+
|
|
279
|
+
:param cron_name: The name of the cron job.
|
|
280
|
+
:param expression: The cron expression that defines the schedule for the cron job.
|
|
281
|
+
:param input: The input data for the workflow.
|
|
282
|
+
:param additional_metadata: Additional metadata for the cron job.
|
|
283
|
+
:param priority: The priority of the cron job. Must be between 1 and 3, inclusive.
|
|
284
|
+
|
|
285
|
+
:returns: A `CronWorkflows` object representing the created cron job.
|
|
286
|
+
"""
|
|
177
287
|
return await self._workflow.aio_create_cron(
|
|
178
288
|
cron_name=cron_name,
|
|
179
289
|
expression=expression,
|
|
180
290
|
input=input,
|
|
181
291
|
additional_metadata=additional_metadata,
|
|
292
|
+
priority=priority,
|
|
182
293
|
)
|
|
183
294
|
|
|
184
295
|
def to_task(self) -> Task[TWorkflowInput, R]:
|