hatchet-sdk 0.42.0__py3-none-any.whl → 0.42.1__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 +10 -8
- hatchet_sdk/clients/dispatcher/action_listener.py +1 -1
- hatchet_sdk/clients/dispatcher/dispatcher.py +2 -2
- hatchet_sdk/clients/rest/tenacity_utils.py +6 -1
- hatchet_sdk/context/context.py +83 -46
- hatchet_sdk/context/worker_context.py +1 -1
- hatchet_sdk/hatchet.py +39 -36
- hatchet_sdk/utils/backoff.py +1 -1
- hatchet_sdk/utils/serialization.py +4 -1
- hatchet_sdk/utils/tracing.py +7 -4
- hatchet_sdk/utils/types.py +8 -0
- hatchet_sdk/utils/typing.py +9 -0
- hatchet_sdk/v2/callable.py +1 -0
- hatchet_sdk/worker/action_listener_process.py +7 -9
- hatchet_sdk/worker/runner/run_loop_manager.py +15 -9
- hatchet_sdk/worker/runner/runner.py +57 -36
- hatchet_sdk/worker/worker.py +96 -59
- hatchet_sdk/workflow.py +80 -26
- {hatchet_sdk-0.42.0.dist-info → hatchet_sdk-0.42.1.dist-info}/METADATA +1 -1
- {hatchet_sdk-0.42.0.dist-info → hatchet_sdk-0.42.1.dist-info}/RECORD +22 -20
- {hatchet_sdk-0.42.0.dist-info → hatchet_sdk-0.42.1.dist-info}/entry_points.txt +1 -0
- {hatchet_sdk-0.42.0.dist-info → hatchet_sdk-0.42.1.dist-info}/WHEEL +0 -0
hatchet_sdk/workflow.py
CHANGED
|
@@ -1,17 +1,51 @@
|
|
|
1
1
|
import functools
|
|
2
|
-
from typing import Any, Callable,
|
|
2
|
+
from typing import Any, Callable, Protocol, Type, TypeVar, Union, cast, get_type_hints
|
|
3
|
+
|
|
4
|
+
from pydantic import BaseModel
|
|
3
5
|
|
|
4
6
|
from hatchet_sdk import ConcurrencyLimitStrategy
|
|
5
|
-
from hatchet_sdk.contracts.workflows_pb2 import (
|
|
7
|
+
from hatchet_sdk.contracts.workflows_pb2 import ( # type: ignore[attr-defined]
|
|
6
8
|
CreateWorkflowJobOpts,
|
|
7
9
|
CreateWorkflowStepOpts,
|
|
8
10
|
CreateWorkflowVersionOpts,
|
|
11
|
+
StickyStrategy,
|
|
9
12
|
WorkflowConcurrencyOpts,
|
|
10
13
|
WorkflowKind,
|
|
11
14
|
)
|
|
12
15
|
from hatchet_sdk.logger import logger
|
|
16
|
+
from hatchet_sdk.utils.typing import is_basemodel_subclass
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class WorkflowStepProtocol(Protocol):
|
|
20
|
+
def __call__(self, *args: Any, **kwargs: Any) -> Any: ...
|
|
21
|
+
|
|
22
|
+
__name__: str
|
|
23
|
+
|
|
24
|
+
_step_name: str
|
|
25
|
+
_step_timeout: str | None
|
|
26
|
+
_step_parents: list[str]
|
|
27
|
+
_step_retries: int | None
|
|
28
|
+
_step_rate_limits: list[str] | None
|
|
29
|
+
_step_desired_worker_labels: dict[str, str]
|
|
30
|
+
_step_backoff_factor: float | None
|
|
31
|
+
_step_backoff_max_seconds: int | None
|
|
32
|
+
|
|
33
|
+
_concurrency_fn_name: str
|
|
34
|
+
_concurrency_max_runs: int | None
|
|
35
|
+
_concurrency_limit_strategy: str | None
|
|
36
|
+
|
|
37
|
+
_on_failure_step_name: str
|
|
38
|
+
_on_failure_step_timeout: str | None
|
|
39
|
+
_on_failure_step_retries: int
|
|
40
|
+
_on_failure_step_rate_limits: list[str] | None
|
|
41
|
+
_on_failure_step_backoff_factor: float | None
|
|
42
|
+
_on_failure_step_backoff_max_seconds: int | None
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
StepsType = list[tuple[str, WorkflowStepProtocol]]
|
|
13
46
|
|
|
14
|
-
|
|
47
|
+
T = TypeVar("T")
|
|
48
|
+
TW = TypeVar("TW", bound="WorkflowInterface")
|
|
15
49
|
|
|
16
50
|
|
|
17
51
|
class ConcurrencyExpression:
|
|
@@ -35,28 +69,48 @@ class ConcurrencyExpression:
|
|
|
35
69
|
self.limit_strategy = limit_strategy
|
|
36
70
|
|
|
37
71
|
|
|
72
|
+
class WorkflowInterface(Protocol):
|
|
73
|
+
def get_name(self, namespace: str) -> str: ...
|
|
74
|
+
|
|
75
|
+
def get_actions(self, namespace: str) -> list[tuple[str, Callable[..., Any]]]: ...
|
|
76
|
+
|
|
77
|
+
def get_create_opts(self, namespace: str) -> Any: ...
|
|
78
|
+
|
|
79
|
+
on_events: list[str]
|
|
80
|
+
on_crons: list[str]
|
|
81
|
+
name: str
|
|
82
|
+
version: str
|
|
83
|
+
timeout: str
|
|
84
|
+
schedule_timeout: str
|
|
85
|
+
sticky: Union[StickyStrategy.Value, None]
|
|
86
|
+
default_priority: int | None
|
|
87
|
+
concurrency_expression: ConcurrencyExpression | None
|
|
88
|
+
input_validator: Type[BaseModel] | None
|
|
89
|
+
|
|
90
|
+
|
|
38
91
|
class WorkflowMeta(type):
|
|
39
|
-
def __new__(
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
92
|
+
def __new__(
|
|
93
|
+
cls: Type["WorkflowMeta"],
|
|
94
|
+
name: str,
|
|
95
|
+
bases: tuple[type, ...],
|
|
96
|
+
attrs: dict[str, Any],
|
|
97
|
+
) -> "WorkflowMeta":
|
|
98
|
+
def _create_steps_actions_list(name: str) -> StepsType:
|
|
99
|
+
return [
|
|
100
|
+
(getattr(func, name), attrs.pop(func_name))
|
|
101
|
+
for func_name, func in list(attrs.items())
|
|
102
|
+
if hasattr(func, name)
|
|
103
|
+
]
|
|
104
|
+
|
|
105
|
+
concurrencyActions = _create_steps_actions_list("_concurrency_fn_name")
|
|
106
|
+
steps = _create_steps_actions_list("_step_name")
|
|
107
|
+
|
|
108
|
+
onFailureSteps = _create_steps_actions_list("_on_failure_step_name")
|
|
55
109
|
|
|
56
110
|
# Define __init__ and get_step_order methods
|
|
57
111
|
original_init = attrs.get("__init__") # Get the original __init__ if it exists
|
|
58
112
|
|
|
59
|
-
def __init__(self, *args, **kwargs):
|
|
113
|
+
def __init__(self: TW, *args: Any, **kwargs: Any) -> None:
|
|
60
114
|
if original_init:
|
|
61
115
|
original_init(self, *args, **kwargs) # Call original __init__
|
|
62
116
|
|
|
@@ -64,7 +118,7 @@ class WorkflowMeta(type):
|
|
|
64
118
|
return f"{namespace}{name.lower()}"
|
|
65
119
|
|
|
66
120
|
@functools.cache
|
|
67
|
-
def get_actions(self, namespace: str) ->
|
|
121
|
+
def get_actions(self: TW, namespace: str) -> StepsType:
|
|
68
122
|
serviceName = get_service_name(namespace)
|
|
69
123
|
func_actions = [
|
|
70
124
|
(serviceName + ":" + func_name, func) for func_name, func in steps
|
|
@@ -87,8 +141,8 @@ class WorkflowMeta(type):
|
|
|
87
141
|
for step_name, step_func in steps:
|
|
88
142
|
attrs[step_name] = step_func
|
|
89
143
|
|
|
90
|
-
def get_name(self, namespace: str):
|
|
91
|
-
return namespace + attrs["name"]
|
|
144
|
+
def get_name(self: TW, namespace: str) -> str:
|
|
145
|
+
return namespace + cast(str, attrs["name"])
|
|
92
146
|
|
|
93
147
|
attrs["get_name"] = get_name
|
|
94
148
|
|
|
@@ -99,11 +153,11 @@ class WorkflowMeta(type):
|
|
|
99
153
|
default_priority = attrs["default_priority"]
|
|
100
154
|
|
|
101
155
|
@functools.cache
|
|
102
|
-
def get_create_opts(self, namespace: str):
|
|
156
|
+
def get_create_opts(self: TW, namespace: str) -> CreateWorkflowVersionOpts:
|
|
103
157
|
serviceName = get_service_name(namespace)
|
|
104
158
|
name = self.get_name(namespace)
|
|
105
159
|
event_triggers = [namespace + event for event in attrs["on_events"]]
|
|
106
|
-
createStepOpts:
|
|
160
|
+
createStepOpts: list[CreateWorkflowStepOpts] = [
|
|
107
161
|
CreateWorkflowStepOpts(
|
|
108
162
|
readable_id=step_name,
|
|
109
163
|
action=serviceName + ":" + step_name,
|
|
@@ -142,7 +196,7 @@ class WorkflowMeta(type):
|
|
|
142
196
|
"Error: Both concurrencyActions and concurrency_expression are defined. Please use only one concurrency configuration method."
|
|
143
197
|
)
|
|
144
198
|
|
|
145
|
-
on_failure_job:
|
|
199
|
+
on_failure_job: list[CreateWorkflowJobOpts] | None = None
|
|
146
200
|
|
|
147
201
|
if len(onFailureSteps) > 0:
|
|
148
202
|
func_name, func = onFailureSteps[0]
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
hatchet_sdk/__init__.py,sha256=R5ogd_Dn_6gA_u9a5W2URNq6eDtN1i56cObBv1tOwyU,9408
|
|
2
2
|
hatchet_sdk/client.py,sha256=ajjLd-gZptVuAx25gG_SdAW8xDA4V7HMIhgYuh9MkVY,3486
|
|
3
|
-
hatchet_sdk/clients/admin.py,sha256=
|
|
4
|
-
hatchet_sdk/clients/dispatcher/action_listener.py,sha256=
|
|
5
|
-
hatchet_sdk/clients/dispatcher/dispatcher.py,sha256=
|
|
3
|
+
hatchet_sdk/clients/admin.py,sha256=rN1T5U7lnrg1FEOUGCD6diqfIsge8SjwnCwn52j0STo,21458
|
|
4
|
+
hatchet_sdk/clients/dispatcher/action_listener.py,sha256=eOq5z29MhC7ynbOOegDRQr-RqDhpS3gfeLswIlZbuGg,15378
|
|
5
|
+
hatchet_sdk/clients/dispatcher/dispatcher.py,sha256=IA_KFqjuxKmGVLuOQNV0SG_dFpX6PeOR8M6Kpl0fU20,6092
|
|
6
6
|
hatchet_sdk/clients/event_ts.py,sha256=ACGvDdfhvK6ZLKdsPxy-PksLhjIU69P9cdH3AxX-X10,728
|
|
7
7
|
hatchet_sdk/clients/events.py,sha256=vPK2UlI1bmrx24mAqGYJQ884yHviVmrGX5qNIBc5-a8,7466
|
|
8
8
|
hatchet_sdk/clients/rest/__init__.py,sha256=IR4dbdTrEse-Eb7wRRwjdKnzKnTU-_HZaKYZzAcLtEI,13840
|
|
@@ -179,14 +179,14 @@ hatchet_sdk/clients/rest/models/workflow_version_definition.py,sha256=e18BUh1XO0
|
|
|
179
179
|
hatchet_sdk/clients/rest/models/workflow_version_meta.py,sha256=TW4R7bAuYAg_LraN-8psdZqp2E8wH9hYyL5Sji86aLk,3791
|
|
180
180
|
hatchet_sdk/clients/rest/models/workflow_workers_count.py,sha256=qhzqfvjjIDyARkiiLGluMIqEmqO-diHTsjlu0Doi0yg,2875
|
|
181
181
|
hatchet_sdk/clients/rest/rest.py,sha256=G83F1k4g_ePzvXW95rApzvaRDQPcaxrj-JmZyq1LvGw,6606
|
|
182
|
-
hatchet_sdk/clients/rest/tenacity_utils.py,sha256=
|
|
182
|
+
hatchet_sdk/clients/rest/tenacity_utils.py,sha256=AmVMjML3pd8qzsWyvaEnaI33zkidou5EK_EQXF69SAE,1032
|
|
183
183
|
hatchet_sdk/clients/rest_client.py,sha256=wYCRQjjZha9XcYg6pdVgrFV4pcli89Y_G45EDEDteCk,21874
|
|
184
184
|
hatchet_sdk/clients/run_event_listener.py,sha256=51WTg52_aISgYPOFPHJ21rb4IO6aEd7Ugp7FCf4HnfM,10184
|
|
185
185
|
hatchet_sdk/clients/workflow_listener.py,sha256=Q_WJcGlZNHJGSpxzDac9wELjgxhP0vLaNTXRy_xnxc8,9466
|
|
186
186
|
hatchet_sdk/connection.py,sha256=593aUGAj7Ouf00lcVwx_pmhdQ9NOC5ANT1Jrf8nwkHs,2165
|
|
187
187
|
hatchet_sdk/context/__init__.py,sha256=Pl_seJ_SJpW34BBZp4KixuZ8GiRK9sJFfegf9u3m7zk,29
|
|
188
|
-
hatchet_sdk/context/context.py,sha256=
|
|
189
|
-
hatchet_sdk/context/worker_context.py,sha256=
|
|
188
|
+
hatchet_sdk/context/context.py,sha256=l0aewPZpncvVzH-L68U-TKH1bMHUuB-4rwXNZ1n69r0,13561
|
|
189
|
+
hatchet_sdk/context/worker_context.py,sha256=1nwq75wnT2zu9Z1fel_TKw0eiMpXJIGAn6HbH1GRVNU,920
|
|
190
190
|
hatchet_sdk/contracts/dispatcher_pb2.py,sha256=W9_Us2_HIdUV5idN2rPwzt4J06JfDeogxwDVvjerk_U,14320
|
|
191
191
|
hatchet_sdk/contracts/dispatcher_pb2.pyi,sha256=6cRfHDhiLElKifrAtdiLFY8QF2_x1KkPBPplG49Ml3I,18240
|
|
192
192
|
hatchet_sdk/contracts/dispatcher_pb2_grpc.py,sha256=4uJkNig8nssJwS7P-lea1YqE4wl0cVWQaJpOndOdaDs,21453
|
|
@@ -198,7 +198,7 @@ hatchet_sdk/contracts/workflows_pb2.pyi,sha256=JS-kP0IL7dtU3HUhJ4PCpAgF3ZLdZ6NbX
|
|
|
198
198
|
hatchet_sdk/contracts/workflows_pb2_grpc.py,sha256=rOC2yF2VqxyGsxHnr1XbKFFh8-eLGic2SXgfS1gU3xM,8864
|
|
199
199
|
hatchet_sdk/features/cron.py,sha256=4lKMH0MqiN8cHJk2jhF0Ueqs6z5ozwJzlOeSeaWqvO0,10217
|
|
200
200
|
hatchet_sdk/features/scheduled.py,sha256=YhEbNWl8dWOH61rXVjAyu8iG1BZqpSkD4kgaxkKIHgY,9504
|
|
201
|
-
hatchet_sdk/hatchet.py,sha256=
|
|
201
|
+
hatchet_sdk/hatchet.py,sha256=UYSHRyqfjvcidOB1PrMLtF1WPacsXoVD_okhjdPxhfI,9599
|
|
202
202
|
hatchet_sdk/labels.py,sha256=OuOtOHeZAd1aYi3j_EhgzIGo1_1wDlYokV74xHSuf8Y,259
|
|
203
203
|
hatchet_sdk/loader.py,sha256=dGs6Tt8wdEgHeCBesbbQsP6ZYiARBvoqwIdXIO1P5Os,7913
|
|
204
204
|
hatchet_sdk/logger.py,sha256=5uOr52T4mImSQm1QvWT8HvZFK5WfPNh3Y1cBQZRFgUQ,333
|
|
@@ -207,22 +207,24 @@ hatchet_sdk/rate_limit.py,sha256=ycFv2NHyBxv31U7h8xVDO661rwif_lfCQf52gWIkB6g,181
|
|
|
207
207
|
hatchet_sdk/semver.py,sha256=PrgBL0TnyXl3p_OK1iSMk9Gpujfh5asQpJ4DHJLCW2k,998
|
|
208
208
|
hatchet_sdk/token.py,sha256=Ap3jnbaPAL10F2G_D71wj7OpBcvrI3RuE0keqXx1lAE,698
|
|
209
209
|
hatchet_sdk/utils/aio_utils.py,sha256=8woLr_rO3CgzpA_2igTcU133oCxNnQoWCt-PZAWrZ_Q,4072
|
|
210
|
-
hatchet_sdk/utils/backoff.py,sha256=
|
|
211
|
-
hatchet_sdk/utils/serialization.py,sha256=
|
|
212
|
-
hatchet_sdk/utils/tracing.py,sha256=
|
|
213
|
-
hatchet_sdk/
|
|
210
|
+
hatchet_sdk/utils/backoff.py,sha256=6B5Rb5nLKw_TqqgpJMYjIBV1PTTtbOMRZCveisVhg_I,353
|
|
211
|
+
hatchet_sdk/utils/serialization.py,sha256=P2Uq0yxg-Cea5Lmf6IOh2r7W17MNF1Hv2qxSny6BUk8,451
|
|
212
|
+
hatchet_sdk/utils/tracing.py,sha256=UjTw2vMLg1p6GjOGwt634nYJaNZh8c70PBxOBVLiDQ4,2261
|
|
213
|
+
hatchet_sdk/utils/types.py,sha256=qhx1OoeXh77AN6s4SMaGpB3zK3hPm7ocv-23JFa6_wE,191
|
|
214
|
+
hatchet_sdk/utils/typing.py,sha256=qXhnoQJXjXwuzyZUQ2H3YQ6YW7vL9D_kvmh2kJM5Z9s,233
|
|
215
|
+
hatchet_sdk/v2/callable.py,sha256=Lnt-kUdM-UJIqCIWZnXgVQHJ11GK9akW66i1oz45WAg,7011
|
|
214
216
|
hatchet_sdk/v2/concurrency.py,sha256=aDr8vunzEJOoe2iGxip6M2fbGTde19kJu-UxCNkXQjM,1282
|
|
215
217
|
hatchet_sdk/v2/hatchet.py,sha256=begVaMZmBllykNuyfAvqhL88m5ELBmx7RrJvsL4xdmY,6872
|
|
216
218
|
hatchet_sdk/worker/__init__.py,sha256=1Ze1seDuXx5yD1IfHmqGFgK5qrRazVW4ZcDVGl-Pddw,61
|
|
217
|
-
hatchet_sdk/worker/action_listener_process.py,sha256=
|
|
218
|
-
hatchet_sdk/worker/runner/run_loop_manager.py,sha256=
|
|
219
|
-
hatchet_sdk/worker/runner/runner.py,sha256=
|
|
219
|
+
hatchet_sdk/worker/action_listener_process.py,sha256=tmlzDgyHWxGl8fJWE9NKqjvhqpGi9SMmOh5dFyiVL-Q,9979
|
|
220
|
+
hatchet_sdk/worker/runner/run_loop_manager.py,sha256=nV7fhNxJKCcrBm0ci118aszF_7AxenBkOTIe1UsBEt4,3490
|
|
221
|
+
hatchet_sdk/worker/runner/runner.py,sha256=fOzfn9Eh6LWhxYl1dRF_EzKBq-EeTIDzeEuX8V0Wm1o,18547
|
|
220
222
|
hatchet_sdk/worker/runner/utils/capture_logs.py,sha256=s_BGxeykelVbusx6u31EPx3vv9c2BHkuBnYcaLW680E,2381
|
|
221
223
|
hatchet_sdk/worker/runner/utils/error_with_traceback.py,sha256=Iih_s8JNqrinXETFJ3ZS88EhaTekfM6m5fqIP7QWoIM,181
|
|
222
|
-
hatchet_sdk/worker/worker.py,sha256=
|
|
223
|
-
hatchet_sdk/workflow.py,sha256=
|
|
224
|
+
hatchet_sdk/worker/worker.py,sha256=fBqTuSnE4lfl-CMTg0FYuw1jE20_CJOwyu2QuzTGdpU,11335
|
|
225
|
+
hatchet_sdk/workflow.py,sha256=qH7lEtR8lvwfP0lHPN2dXJjEh2xmHST19ADW7z82OgM,9209
|
|
224
226
|
hatchet_sdk/workflow_run.py,sha256=BwK5cefvXXvyQ1Ednj_7LeejMwQJqWnvUC_FTBmJNxk,1805
|
|
225
|
-
hatchet_sdk-0.42.
|
|
226
|
-
hatchet_sdk-0.42.
|
|
227
|
-
hatchet_sdk-0.42.
|
|
228
|
-
hatchet_sdk-0.42.
|
|
227
|
+
hatchet_sdk-0.42.1.dist-info/METADATA,sha256=BaDtr-PCud9AbcDoCGbMWi-P7Q-z29y2VtJlapr9m_8,1471
|
|
228
|
+
hatchet_sdk-0.42.1.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
|
|
229
|
+
hatchet_sdk-0.42.1.dist-info/entry_points.txt,sha256=CBdxVD3JfWwRLJsOlSKj5OJh2gY_64rQkyXw5DfNpQ4,930
|
|
230
|
+
hatchet_sdk-0.42.1.dist-info/RECORD,,
|
|
@@ -15,6 +15,7 @@ logger=examples.logger.worker:main
|
|
|
15
15
|
manual_trigger=examples.manual_trigger.worker:main
|
|
16
16
|
on_failure=examples.on_failure.worker:main
|
|
17
17
|
programatic_replay=examples.programatic_replay.worker:main
|
|
18
|
+
pydantic=examples.pydantic.worker:main
|
|
18
19
|
rate_limit=examples.rate_limit.worker:main
|
|
19
20
|
retries_with_backoff=examples.retries_with_backoff.worker:main
|
|
20
21
|
simple=examples.simple.worker:main
|
|
File without changes
|