hatchet-sdk 0.41.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/contracts/dispatcher_pb2.py +71 -67
- hatchet_sdk/contracts/dispatcher_pb2.pyi +29 -2
- hatchet_sdk/contracts/workflows_pb2.py +42 -40
- hatchet_sdk/contracts/workflows_pb2.pyi +22 -6
- hatchet_sdk/hatchet.py +44 -32
- 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 +84 -26
- {hatchet_sdk-0.41.0.dist-info → hatchet_sdk-0.42.1.dist-info}/METADATA +1 -1
- {hatchet_sdk-0.41.0.dist-info → hatchet_sdk-0.42.1.dist-info}/RECORD +26 -24
- {hatchet_sdk-0.41.0.dist-info → hatchet_sdk-0.42.1.dist-info}/entry_points.txt +2 -0
- {hatchet_sdk-0.41.0.dist-info → hatchet_sdk-0.42.1.dist-info}/WHEEL +0 -0
|
@@ -9,6 +9,13 @@ from typing import ClassVar as _ClassVar, Iterable as _Iterable, Mapping as _Map
|
|
|
9
9
|
|
|
10
10
|
DESCRIPTOR: _descriptor.FileDescriptor
|
|
11
11
|
|
|
12
|
+
class SDKS(int, metaclass=_enum_type_wrapper.EnumTypeWrapper):
|
|
13
|
+
__slots__ = ()
|
|
14
|
+
UNKNOWN: _ClassVar[SDKS]
|
|
15
|
+
GO: _ClassVar[SDKS]
|
|
16
|
+
PYTHON: _ClassVar[SDKS]
|
|
17
|
+
TYPESCRIPT: _ClassVar[SDKS]
|
|
18
|
+
|
|
12
19
|
class ActionType(int, metaclass=_enum_type_wrapper.EnumTypeWrapper):
|
|
13
20
|
__slots__ = ()
|
|
14
21
|
START_STEP_RUN: _ClassVar[ActionType]
|
|
@@ -49,6 +56,10 @@ class ResourceEventType(int, metaclass=_enum_type_wrapper.EnumTypeWrapper):
|
|
|
49
56
|
class WorkflowRunEventType(int, metaclass=_enum_type_wrapper.EnumTypeWrapper):
|
|
50
57
|
__slots__ = ()
|
|
51
58
|
WORKFLOW_RUN_EVENT_TYPE_FINISHED: _ClassVar[WorkflowRunEventType]
|
|
59
|
+
UNKNOWN: SDKS
|
|
60
|
+
GO: SDKS
|
|
61
|
+
PYTHON: SDKS
|
|
62
|
+
TYPESCRIPT: SDKS
|
|
52
63
|
START_STEP_RUN: ActionType
|
|
53
64
|
CANCEL_STEP_RUN: ActionType
|
|
54
65
|
START_GET_GROUP_KEY: ActionType
|
|
@@ -81,8 +92,22 @@ class WorkerLabels(_message.Message):
|
|
|
81
92
|
intValue: int
|
|
82
93
|
def __init__(self, strValue: _Optional[str] = ..., intValue: _Optional[int] = ...) -> None: ...
|
|
83
94
|
|
|
95
|
+
class RuntimeInfo(_message.Message):
|
|
96
|
+
__slots__ = ("sdkVersion", "language", "languageVersion", "os", "extra")
|
|
97
|
+
SDKVERSION_FIELD_NUMBER: _ClassVar[int]
|
|
98
|
+
LANGUAGE_FIELD_NUMBER: _ClassVar[int]
|
|
99
|
+
LANGUAGEVERSION_FIELD_NUMBER: _ClassVar[int]
|
|
100
|
+
OS_FIELD_NUMBER: _ClassVar[int]
|
|
101
|
+
EXTRA_FIELD_NUMBER: _ClassVar[int]
|
|
102
|
+
sdkVersion: str
|
|
103
|
+
language: SDKS
|
|
104
|
+
languageVersion: str
|
|
105
|
+
os: str
|
|
106
|
+
extra: str
|
|
107
|
+
def __init__(self, sdkVersion: _Optional[str] = ..., language: _Optional[_Union[SDKS, str]] = ..., languageVersion: _Optional[str] = ..., os: _Optional[str] = ..., extra: _Optional[str] = ...) -> None: ...
|
|
108
|
+
|
|
84
109
|
class WorkerRegisterRequest(_message.Message):
|
|
85
|
-
__slots__ = ("workerName", "actions", "services", "maxRuns", "labels", "webhookId")
|
|
110
|
+
__slots__ = ("workerName", "actions", "services", "maxRuns", "labels", "webhookId", "runtimeInfo")
|
|
86
111
|
class LabelsEntry(_message.Message):
|
|
87
112
|
__slots__ = ("key", "value")
|
|
88
113
|
KEY_FIELD_NUMBER: _ClassVar[int]
|
|
@@ -96,13 +121,15 @@ class WorkerRegisterRequest(_message.Message):
|
|
|
96
121
|
MAXRUNS_FIELD_NUMBER: _ClassVar[int]
|
|
97
122
|
LABELS_FIELD_NUMBER: _ClassVar[int]
|
|
98
123
|
WEBHOOKID_FIELD_NUMBER: _ClassVar[int]
|
|
124
|
+
RUNTIMEINFO_FIELD_NUMBER: _ClassVar[int]
|
|
99
125
|
workerName: str
|
|
100
126
|
actions: _containers.RepeatedScalarFieldContainer[str]
|
|
101
127
|
services: _containers.RepeatedScalarFieldContainer[str]
|
|
102
128
|
maxRuns: int
|
|
103
129
|
labels: _containers.MessageMap[str, WorkerLabels]
|
|
104
130
|
webhookId: str
|
|
105
|
-
|
|
131
|
+
runtimeInfo: RuntimeInfo
|
|
132
|
+
def __init__(self, workerName: _Optional[str] = ..., actions: _Optional[_Iterable[str]] = ..., services: _Optional[_Iterable[str]] = ..., maxRuns: _Optional[int] = ..., labels: _Optional[_Mapping[str, WorkerLabels]] = ..., webhookId: _Optional[str] = ..., runtimeInfo: _Optional[_Union[RuntimeInfo, _Mapping]] = ...) -> None: ...
|
|
106
133
|
|
|
107
134
|
class WorkerRegisterResponse(_message.Message):
|
|
108
135
|
__slots__ = ("tenantId", "workerId", "workerName")
|
|
@@ -15,7 +15,7 @@ _sym_db = _symbol_database.Default()
|
|
|
15
15
|
from google.protobuf import timestamp_pb2 as google_dot_protobuf_dot_timestamp__pb2
|
|
16
16
|
|
|
17
17
|
|
|
18
|
-
DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x0fworkflows.proto\x1a\x1fgoogle/protobuf/timestamp.proto\">\n\x12PutWorkflowRequest\x12(\n\x04opts\x18\x01 \x01(\x0b\x32\x1a.CreateWorkflowVersionOpts\"\xbf\x04\n\x19\x43reateWorkflowVersionOpts\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x13\n\x0b\x64\x65scription\x18\x02 \x01(\t\x12\x0f\n\x07version\x18\x03 \x01(\t\x12\x16\n\x0e\x65vent_triggers\x18\x04 \x03(\t\x12\x15\n\rcron_triggers\x18\x05 \x03(\t\x12\x36\n\x12scheduled_triggers\x18\x06 \x03(\x0b\x32\x1a.google.protobuf.Timestamp\x12$\n\x04jobs\x18\x07 \x03(\x0b\x32\x16.CreateWorkflowJobOpts\x12-\n\x0b\x63oncurrency\x18\x08 \x01(\x0b\x32\x18.WorkflowConcurrencyOpts\x12\x1d\n\x10schedule_timeout\x18\t \x01(\tH\x00\x88\x01\x01\x12\x17\n\ncron_input\x18\n \x01(\tH\x01\x88\x01\x01\x12\x33\n\x0eon_failure_job\x18\x0b \x01(\x0b\x32\x16.CreateWorkflowJobOptsH\x02\x88\x01\x01\x12$\n\x06sticky\x18\x0c \x01(\x0e\x32\x0f.StickyStrategyH\x03\x88\x01\x01\x12 \n\x04kind\x18\r \x01(\x0e\x32\r.WorkflowKindH\x04\x88\x01\x01\x12\x1d\n\x10\x64\x65\x66\x61ult_priority\x18\x0e \x01(\x05H\x05\x88\x01\x01\x42\x13\n\x11_schedule_timeoutB\r\n\x0b_cron_inputB\x11\n\x0f_on_failure_jobB\t\n\x07_stickyB\x07\n\x05_kindB\x13\n\x11_default_priority\"\xd0\x01\n\x17WorkflowConcurrencyOpts\x12\x13\n\x06\x61\x63tion\x18\x01 \x01(\tH\x00\x88\x01\x01\x12\x15\n\x08max_runs\x18\x02 \x01(\x05H\x01\x88\x01\x01\x12\x36\n\x0elimit_strategy\x18\x03 \x01(\x0e\x32\x19.ConcurrencyLimitStrategyH\x02\x88\x01\x01\x12\x17\n\nexpression\x18\x04 \x01(\tH\x03\x88\x01\x01\x42\t\n\x07_actionB\x0b\n\t_max_runsB\x11\n\x0f_limit_strategyB\r\n\x0b_expression\"h\n\x15\x43reateWorkflowJobOpts\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x13\n\x0b\x64\x65scription\x18\x02 \x01(\t\x12&\n\x05steps\x18\x04 \x03(\x0b\x32\x17.CreateWorkflowStepOptsJ\x04\x08\x03\x10\x04\"\xe1\x01\n\x13\x44\x65siredWorkerLabels\x12\x15\n\x08strValue\x18\x01 \x01(\tH\x00\x88\x01\x01\x12\x15\n\x08intValue\x18\x02 \x01(\x05H\x01\x88\x01\x01\x12\x15\n\x08required\x18\x03 \x01(\x08H\x02\x88\x01\x01\x12/\n\ncomparator\x18\x04 \x01(\x0e\x32\x16.WorkerLabelComparatorH\x03\x88\x01\x01\x12\x13\n\x06weight\x18\x05 \x01(\x05H\x04\x88\x01\x01\x42\x0b\n\t_strValueB\x0b\n\t_intValueB\x0b\n\t_requiredB\r\n\x0b_comparatorB\t\n\x07_weight\"\
|
|
18
|
+
DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x0fworkflows.proto\x1a\x1fgoogle/protobuf/timestamp.proto\">\n\x12PutWorkflowRequest\x12(\n\x04opts\x18\x01 \x01(\x0b\x32\x1a.CreateWorkflowVersionOpts\"\xbf\x04\n\x19\x43reateWorkflowVersionOpts\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x13\n\x0b\x64\x65scription\x18\x02 \x01(\t\x12\x0f\n\x07version\x18\x03 \x01(\t\x12\x16\n\x0e\x65vent_triggers\x18\x04 \x03(\t\x12\x15\n\rcron_triggers\x18\x05 \x03(\t\x12\x36\n\x12scheduled_triggers\x18\x06 \x03(\x0b\x32\x1a.google.protobuf.Timestamp\x12$\n\x04jobs\x18\x07 \x03(\x0b\x32\x16.CreateWorkflowJobOpts\x12-\n\x0b\x63oncurrency\x18\x08 \x01(\x0b\x32\x18.WorkflowConcurrencyOpts\x12\x1d\n\x10schedule_timeout\x18\t \x01(\tH\x00\x88\x01\x01\x12\x17\n\ncron_input\x18\n \x01(\tH\x01\x88\x01\x01\x12\x33\n\x0eon_failure_job\x18\x0b \x01(\x0b\x32\x16.CreateWorkflowJobOptsH\x02\x88\x01\x01\x12$\n\x06sticky\x18\x0c \x01(\x0e\x32\x0f.StickyStrategyH\x03\x88\x01\x01\x12 \n\x04kind\x18\r \x01(\x0e\x32\r.WorkflowKindH\x04\x88\x01\x01\x12\x1d\n\x10\x64\x65\x66\x61ult_priority\x18\x0e \x01(\x05H\x05\x88\x01\x01\x42\x13\n\x11_schedule_timeoutB\r\n\x0b_cron_inputB\x11\n\x0f_on_failure_jobB\t\n\x07_stickyB\x07\n\x05_kindB\x13\n\x11_default_priority\"\xd0\x01\n\x17WorkflowConcurrencyOpts\x12\x13\n\x06\x61\x63tion\x18\x01 \x01(\tH\x00\x88\x01\x01\x12\x15\n\x08max_runs\x18\x02 \x01(\x05H\x01\x88\x01\x01\x12\x36\n\x0elimit_strategy\x18\x03 \x01(\x0e\x32\x19.ConcurrencyLimitStrategyH\x02\x88\x01\x01\x12\x17\n\nexpression\x18\x04 \x01(\tH\x03\x88\x01\x01\x42\t\n\x07_actionB\x0b\n\t_max_runsB\x11\n\x0f_limit_strategyB\r\n\x0b_expression\"h\n\x15\x43reateWorkflowJobOpts\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x13\n\x0b\x64\x65scription\x18\x02 \x01(\t\x12&\n\x05steps\x18\x04 \x03(\x0b\x32\x17.CreateWorkflowStepOptsJ\x04\x08\x03\x10\x04\"\xe1\x01\n\x13\x44\x65siredWorkerLabels\x12\x15\n\x08strValue\x18\x01 \x01(\tH\x00\x88\x01\x01\x12\x15\n\x08intValue\x18\x02 \x01(\x05H\x01\x88\x01\x01\x12\x15\n\x08required\x18\x03 \x01(\x08H\x02\x88\x01\x01\x12/\n\ncomparator\x18\x04 \x01(\x0e\x32\x16.WorkerLabelComparatorH\x03\x88\x01\x01\x12\x13\n\x06weight\x18\x05 \x01(\x05H\x04\x88\x01\x01\x42\x0b\n\t_strValueB\x0b\n\t_intValueB\x0b\n\t_requiredB\r\n\x0b_comparatorB\t\n\x07_weight\"\xb5\x03\n\x16\x43reateWorkflowStepOpts\x12\x13\n\x0breadable_id\x18\x01 \x01(\t\x12\x0e\n\x06\x61\x63tion\x18\x02 \x01(\t\x12\x0f\n\x07timeout\x18\x03 \x01(\t\x12\x0e\n\x06inputs\x18\x04 \x01(\t\x12\x0f\n\x07parents\x18\x05 \x03(\t\x12\x11\n\tuser_data\x18\x06 \x01(\t\x12\x0f\n\x07retries\x18\x07 \x01(\x05\x12)\n\x0brate_limits\x18\x08 \x03(\x0b\x32\x14.CreateStepRateLimit\x12@\n\rworker_labels\x18\t \x03(\x0b\x32).CreateWorkflowStepOpts.WorkerLabelsEntry\x12\x1b\n\x0e\x62\x61\x63koff_factor\x18\n \x01(\x02H\x00\x88\x01\x01\x12 \n\x13\x62\x61\x63koff_max_seconds\x18\x0b \x01(\x05H\x01\x88\x01\x01\x1aI\n\x11WorkerLabelsEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12#\n\x05value\x18\x02 \x01(\x0b\x32\x14.DesiredWorkerLabels:\x02\x38\x01\x42\x11\n\x0f_backoff_factorB\x16\n\x14_backoff_max_seconds\"\xfa\x01\n\x13\x43reateStepRateLimit\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\x12\n\x05units\x18\x02 \x01(\x05H\x00\x88\x01\x01\x12\x15\n\x08key_expr\x18\x03 \x01(\tH\x01\x88\x01\x01\x12\x17\n\nunits_expr\x18\x04 \x01(\tH\x02\x88\x01\x01\x12\x1e\n\x11limit_values_expr\x18\x05 \x01(\tH\x03\x88\x01\x01\x12)\n\x08\x64uration\x18\x06 \x01(\x0e\x32\x12.RateLimitDurationH\x04\x88\x01\x01\x42\x08\n\x06_unitsB\x0b\n\t_key_exprB\r\n\x0b_units_exprB\x14\n\x12_limit_values_exprB\x0b\n\t_duration\"\x16\n\x14ListWorkflowsRequest\"\xcd\x02\n\x17ScheduleWorkflowRequest\x12\x0c\n\x04name\x18\x01 \x01(\t\x12-\n\tschedules\x18\x02 \x03(\x0b\x32\x1a.google.protobuf.Timestamp\x12\r\n\x05input\x18\x03 \x01(\t\x12\x16\n\tparent_id\x18\x04 \x01(\tH\x00\x88\x01\x01\x12\x1f\n\x12parent_step_run_id\x18\x05 \x01(\tH\x01\x88\x01\x01\x12\x18\n\x0b\x63hild_index\x18\x06 \x01(\x05H\x02\x88\x01\x01\x12\x16\n\tchild_key\x18\x07 \x01(\tH\x03\x88\x01\x01\x12 \n\x13\x61\x64\x64itional_metadata\x18\x08 \x01(\tH\x04\x88\x01\x01\x42\x0c\n\n_parent_idB\x15\n\x13_parent_step_run_idB\x0e\n\x0c_child_indexB\x0c\n\n_child_keyB\x16\n\x14_additional_metadata\"O\n\x11ScheduledWorkflow\x12\n\n\x02id\x18\x01 \x01(\t\x12.\n\ntrigger_at\x18\x02 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\"\xe3\x01\n\x0fWorkflowVersion\x12\n\n\x02id\x18\x01 \x01(\t\x12.\n\ncreated_at\x18\x02 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\x12.\n\nupdated_at\x18\x03 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\x12\x0f\n\x07version\x18\x05 \x01(\t\x12\r\n\x05order\x18\x06 \x01(\x03\x12\x13\n\x0bworkflow_id\x18\x07 \x01(\t\x12/\n\x13scheduled_workflows\x18\x08 \x03(\x0b\x32\x12.ScheduledWorkflow\"?\n\x17WorkflowTriggerEventRef\x12\x11\n\tparent_id\x18\x01 \x01(\t\x12\x11\n\tevent_key\x18\x02 \x01(\t\"9\n\x16WorkflowTriggerCronRef\x12\x11\n\tparent_id\x18\x01 \x01(\t\x12\x0c\n\x04\x63ron\x18\x02 \x01(\t\"H\n\x1a\x42ulkTriggerWorkflowRequest\x12*\n\tworkflows\x18\x01 \x03(\x0b\x32\x17.TriggerWorkflowRequest\"7\n\x1b\x42ulkTriggerWorkflowResponse\x12\x18\n\x10workflow_run_ids\x18\x01 \x03(\t\"\xf7\x02\n\x16TriggerWorkflowRequest\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\r\n\x05input\x18\x02 \x01(\t\x12\x16\n\tparent_id\x18\x03 \x01(\tH\x00\x88\x01\x01\x12\x1f\n\x12parent_step_run_id\x18\x04 \x01(\tH\x01\x88\x01\x01\x12\x18\n\x0b\x63hild_index\x18\x05 \x01(\x05H\x02\x88\x01\x01\x12\x16\n\tchild_key\x18\x06 \x01(\tH\x03\x88\x01\x01\x12 \n\x13\x61\x64\x64itional_metadata\x18\x07 \x01(\tH\x04\x88\x01\x01\x12\x1e\n\x11\x64\x65sired_worker_id\x18\x08 \x01(\tH\x05\x88\x01\x01\x12\x15\n\x08priority\x18\t \x01(\x05H\x06\x88\x01\x01\x42\x0c\n\n_parent_idB\x15\n\x13_parent_step_run_idB\x0e\n\x0c_child_indexB\x0c\n\n_child_keyB\x16\n\x14_additional_metadataB\x14\n\x12_desired_worker_idB\x0b\n\t_priority\"2\n\x17TriggerWorkflowResponse\x12\x17\n\x0fworkflow_run_id\x18\x01 \x01(\t\"W\n\x13PutRateLimitRequest\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05limit\x18\x02 \x01(\x05\x12$\n\x08\x64uration\x18\x03 \x01(\x0e\x32\x12.RateLimitDuration\"\x16\n\x14PutRateLimitResponse*$\n\x0eStickyStrategy\x12\x08\n\x04SOFT\x10\x00\x12\x08\n\x04HARD\x10\x01*2\n\x0cWorkflowKind\x12\x0c\n\x08\x46UNCTION\x10\x00\x12\x0b\n\x07\x44URABLE\x10\x01\x12\x07\n\x03\x44\x41G\x10\x02*l\n\x18\x43oncurrencyLimitStrategy\x12\x16\n\x12\x43\x41NCEL_IN_PROGRESS\x10\x00\x12\x0f\n\x0b\x44ROP_NEWEST\x10\x01\x12\x10\n\x0cQUEUE_NEWEST\x10\x02\x12\x15\n\x11GROUP_ROUND_ROBIN\x10\x03*\x85\x01\n\x15WorkerLabelComparator\x12\t\n\x05\x45QUAL\x10\x00\x12\r\n\tNOT_EQUAL\x10\x01\x12\x10\n\x0cGREATER_THAN\x10\x02\x12\x19\n\x15GREATER_THAN_OR_EQUAL\x10\x03\x12\r\n\tLESS_THAN\x10\x04\x12\x16\n\x12LESS_THAN_OR_EQUAL\x10\x05*]\n\x11RateLimitDuration\x12\n\n\x06SECOND\x10\x00\x12\n\n\x06MINUTE\x10\x01\x12\x08\n\x04HOUR\x10\x02\x12\x07\n\x03\x44\x41Y\x10\x03\x12\x08\n\x04WEEK\x10\x04\x12\t\n\x05MONTH\x10\x05\x12\x08\n\x04YEAR\x10\x06\x32\xdc\x02\n\x0fWorkflowService\x12\x34\n\x0bPutWorkflow\x12\x13.PutWorkflowRequest\x1a\x10.WorkflowVersion\x12>\n\x10ScheduleWorkflow\x12\x18.ScheduleWorkflowRequest\x1a\x10.WorkflowVersion\x12\x44\n\x0fTriggerWorkflow\x12\x17.TriggerWorkflowRequest\x1a\x18.TriggerWorkflowResponse\x12P\n\x13\x42ulkTriggerWorkflow\x12\x1b.BulkTriggerWorkflowRequest\x1a\x1c.BulkTriggerWorkflowResponse\x12;\n\x0cPutRateLimit\x12\x14.PutRateLimitRequest\x1a\x15.PutRateLimitResponseBBZ@github.com/hatchet-dev/hatchet/internal/services/admin/contractsb\x06proto3')
|
|
19
19
|
|
|
20
20
|
_globals = globals()
|
|
21
21
|
_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
|
|
@@ -25,16 +25,16 @@ if _descriptor._USE_C_DESCRIPTORS == False:
|
|
|
25
25
|
_globals['DESCRIPTOR']._serialized_options = b'Z@github.com/hatchet-dev/hatchet/internal/services/admin/contracts'
|
|
26
26
|
_globals['_CREATEWORKFLOWSTEPOPTS_WORKERLABELSENTRY']._options = None
|
|
27
27
|
_globals['_CREATEWORKFLOWSTEPOPTS_WORKERLABELSENTRY']._serialized_options = b'8\001'
|
|
28
|
-
_globals['_STICKYSTRATEGY']._serialized_start=
|
|
29
|
-
_globals['_STICKYSTRATEGY']._serialized_end=
|
|
30
|
-
_globals['_WORKFLOWKIND']._serialized_start=
|
|
31
|
-
_globals['_WORKFLOWKIND']._serialized_end=
|
|
32
|
-
_globals['_CONCURRENCYLIMITSTRATEGY']._serialized_start=
|
|
33
|
-
_globals['_CONCURRENCYLIMITSTRATEGY']._serialized_end=
|
|
34
|
-
_globals['_WORKERLABELCOMPARATOR']._serialized_start=
|
|
35
|
-
_globals['_WORKERLABELCOMPARATOR']._serialized_end=
|
|
36
|
-
_globals['_RATELIMITDURATION']._serialized_start=
|
|
37
|
-
_globals['_RATELIMITDURATION']._serialized_end=
|
|
28
|
+
_globals['_STICKYSTRATEGY']._serialized_start=3401
|
|
29
|
+
_globals['_STICKYSTRATEGY']._serialized_end=3437
|
|
30
|
+
_globals['_WORKFLOWKIND']._serialized_start=3439
|
|
31
|
+
_globals['_WORKFLOWKIND']._serialized_end=3489
|
|
32
|
+
_globals['_CONCURRENCYLIMITSTRATEGY']._serialized_start=3491
|
|
33
|
+
_globals['_CONCURRENCYLIMITSTRATEGY']._serialized_end=3599
|
|
34
|
+
_globals['_WORKERLABELCOMPARATOR']._serialized_start=3602
|
|
35
|
+
_globals['_WORKERLABELCOMPARATOR']._serialized_end=3735
|
|
36
|
+
_globals['_RATELIMITDURATION']._serialized_start=3737
|
|
37
|
+
_globals['_RATELIMITDURATION']._serialized_end=3830
|
|
38
38
|
_globals['_PUTWORKFLOWREQUEST']._serialized_start=52
|
|
39
39
|
_globals['_PUTWORKFLOWREQUEST']._serialized_end=114
|
|
40
40
|
_globals['_CREATEWORKFLOWVERSIONOPTS']._serialized_start=117
|
|
@@ -46,33 +46,35 @@ if _descriptor._USE_C_DESCRIPTORS == False:
|
|
|
46
46
|
_globals['_DESIREDWORKERLABELS']._serialized_start=1012
|
|
47
47
|
_globals['_DESIREDWORKERLABELS']._serialized_end=1237
|
|
48
48
|
_globals['_CREATEWORKFLOWSTEPOPTS']._serialized_start=1240
|
|
49
|
-
_globals['_CREATEWORKFLOWSTEPOPTS']._serialized_end=
|
|
50
|
-
_globals['_CREATEWORKFLOWSTEPOPTS_WORKERLABELSENTRY']._serialized_start=
|
|
51
|
-
_globals['_CREATEWORKFLOWSTEPOPTS_WORKERLABELSENTRY']._serialized_end=
|
|
52
|
-
_globals['_CREATESTEPRATELIMIT']._serialized_start=
|
|
53
|
-
_globals['_CREATESTEPRATELIMIT']._serialized_end=
|
|
54
|
-
_globals['_LISTWORKFLOWSREQUEST']._serialized_start=
|
|
55
|
-
_globals['_LISTWORKFLOWSREQUEST']._serialized_end=
|
|
56
|
-
_globals['_SCHEDULEWORKFLOWREQUEST']._serialized_start=
|
|
57
|
-
_globals['_SCHEDULEWORKFLOWREQUEST']._serialized_end=
|
|
58
|
-
_globals['
|
|
59
|
-
_globals['
|
|
60
|
-
_globals['
|
|
61
|
-
_globals['
|
|
62
|
-
_globals['
|
|
63
|
-
_globals['
|
|
64
|
-
_globals['
|
|
65
|
-
_globals['
|
|
66
|
-
_globals['
|
|
67
|
-
_globals['
|
|
68
|
-
_globals['
|
|
69
|
-
_globals['
|
|
70
|
-
_globals['
|
|
71
|
-
_globals['
|
|
72
|
-
_globals['
|
|
73
|
-
_globals['
|
|
74
|
-
_globals['
|
|
75
|
-
_globals['
|
|
76
|
-
_globals['
|
|
77
|
-
_globals['
|
|
49
|
+
_globals['_CREATEWORKFLOWSTEPOPTS']._serialized_end=1677
|
|
50
|
+
_globals['_CREATEWORKFLOWSTEPOPTS_WORKERLABELSENTRY']._serialized_start=1561
|
|
51
|
+
_globals['_CREATEWORKFLOWSTEPOPTS_WORKERLABELSENTRY']._serialized_end=1634
|
|
52
|
+
_globals['_CREATESTEPRATELIMIT']._serialized_start=1680
|
|
53
|
+
_globals['_CREATESTEPRATELIMIT']._serialized_end=1930
|
|
54
|
+
_globals['_LISTWORKFLOWSREQUEST']._serialized_start=1932
|
|
55
|
+
_globals['_LISTWORKFLOWSREQUEST']._serialized_end=1954
|
|
56
|
+
_globals['_SCHEDULEWORKFLOWREQUEST']._serialized_start=1957
|
|
57
|
+
_globals['_SCHEDULEWORKFLOWREQUEST']._serialized_end=2290
|
|
58
|
+
_globals['_SCHEDULEDWORKFLOW']._serialized_start=2292
|
|
59
|
+
_globals['_SCHEDULEDWORKFLOW']._serialized_end=2371
|
|
60
|
+
_globals['_WORKFLOWVERSION']._serialized_start=2374
|
|
61
|
+
_globals['_WORKFLOWVERSION']._serialized_end=2601
|
|
62
|
+
_globals['_WORKFLOWTRIGGEREVENTREF']._serialized_start=2603
|
|
63
|
+
_globals['_WORKFLOWTRIGGEREVENTREF']._serialized_end=2666
|
|
64
|
+
_globals['_WORKFLOWTRIGGERCRONREF']._serialized_start=2668
|
|
65
|
+
_globals['_WORKFLOWTRIGGERCRONREF']._serialized_end=2725
|
|
66
|
+
_globals['_BULKTRIGGERWORKFLOWREQUEST']._serialized_start=2727
|
|
67
|
+
_globals['_BULKTRIGGERWORKFLOWREQUEST']._serialized_end=2799
|
|
68
|
+
_globals['_BULKTRIGGERWORKFLOWRESPONSE']._serialized_start=2801
|
|
69
|
+
_globals['_BULKTRIGGERWORKFLOWRESPONSE']._serialized_end=2856
|
|
70
|
+
_globals['_TRIGGERWORKFLOWREQUEST']._serialized_start=2859
|
|
71
|
+
_globals['_TRIGGERWORKFLOWREQUEST']._serialized_end=3234
|
|
72
|
+
_globals['_TRIGGERWORKFLOWRESPONSE']._serialized_start=3236
|
|
73
|
+
_globals['_TRIGGERWORKFLOWRESPONSE']._serialized_end=3286
|
|
74
|
+
_globals['_PUTRATELIMITREQUEST']._serialized_start=3288
|
|
75
|
+
_globals['_PUTRATELIMITREQUEST']._serialized_end=3375
|
|
76
|
+
_globals['_PUTRATELIMITRESPONSE']._serialized_start=3377
|
|
77
|
+
_globals['_PUTRATELIMITRESPONSE']._serialized_end=3399
|
|
78
|
+
_globals['_WORKFLOWSERVICE']._serialized_start=3833
|
|
79
|
+
_globals['_WORKFLOWSERVICE']._serialized_end=4181
|
|
78
80
|
# @@protoc_insertion_point(module_scope)
|
|
@@ -143,7 +143,7 @@ class DesiredWorkerLabels(_message.Message):
|
|
|
143
143
|
def __init__(self, strValue: _Optional[str] = ..., intValue: _Optional[int] = ..., required: bool = ..., comparator: _Optional[_Union[WorkerLabelComparator, str]] = ..., weight: _Optional[int] = ...) -> None: ...
|
|
144
144
|
|
|
145
145
|
class CreateWorkflowStepOpts(_message.Message):
|
|
146
|
-
__slots__ = ("readable_id", "action", "timeout", "inputs", "parents", "user_data", "retries", "rate_limits", "worker_labels")
|
|
146
|
+
__slots__ = ("readable_id", "action", "timeout", "inputs", "parents", "user_data", "retries", "rate_limits", "worker_labels", "backoff_factor", "backoff_max_seconds")
|
|
147
147
|
class WorkerLabelsEntry(_message.Message):
|
|
148
148
|
__slots__ = ("key", "value")
|
|
149
149
|
KEY_FIELD_NUMBER: _ClassVar[int]
|
|
@@ -160,6 +160,8 @@ class CreateWorkflowStepOpts(_message.Message):
|
|
|
160
160
|
RETRIES_FIELD_NUMBER: _ClassVar[int]
|
|
161
161
|
RATE_LIMITS_FIELD_NUMBER: _ClassVar[int]
|
|
162
162
|
WORKER_LABELS_FIELD_NUMBER: _ClassVar[int]
|
|
163
|
+
BACKOFF_FACTOR_FIELD_NUMBER: _ClassVar[int]
|
|
164
|
+
BACKOFF_MAX_SECONDS_FIELD_NUMBER: _ClassVar[int]
|
|
163
165
|
readable_id: str
|
|
164
166
|
action: str
|
|
165
167
|
timeout: str
|
|
@@ -169,7 +171,9 @@ class CreateWorkflowStepOpts(_message.Message):
|
|
|
169
171
|
retries: int
|
|
170
172
|
rate_limits: _containers.RepeatedCompositeFieldContainer[CreateStepRateLimit]
|
|
171
173
|
worker_labels: _containers.MessageMap[str, DesiredWorkerLabels]
|
|
172
|
-
|
|
174
|
+
backoff_factor: float
|
|
175
|
+
backoff_max_seconds: int
|
|
176
|
+
def __init__(self, readable_id: _Optional[str] = ..., action: _Optional[str] = ..., timeout: _Optional[str] = ..., inputs: _Optional[str] = ..., parents: _Optional[_Iterable[str]] = ..., user_data: _Optional[str] = ..., retries: _Optional[int] = ..., rate_limits: _Optional[_Iterable[_Union[CreateStepRateLimit, _Mapping]]] = ..., worker_labels: _Optional[_Mapping[str, DesiredWorkerLabels]] = ..., backoff_factor: _Optional[float] = ..., backoff_max_seconds: _Optional[int] = ...) -> None: ...
|
|
173
177
|
|
|
174
178
|
class CreateStepRateLimit(_message.Message):
|
|
175
179
|
__slots__ = ("key", "units", "key_expr", "units_expr", "limit_values_expr", "duration")
|
|
@@ -192,7 +196,7 @@ class ListWorkflowsRequest(_message.Message):
|
|
|
192
196
|
def __init__(self) -> None: ...
|
|
193
197
|
|
|
194
198
|
class ScheduleWorkflowRequest(_message.Message):
|
|
195
|
-
__slots__ = ("name", "schedules", "input", "parent_id", "parent_step_run_id", "child_index", "child_key")
|
|
199
|
+
__slots__ = ("name", "schedules", "input", "parent_id", "parent_step_run_id", "child_index", "child_key", "additional_metadata")
|
|
196
200
|
NAME_FIELD_NUMBER: _ClassVar[int]
|
|
197
201
|
SCHEDULES_FIELD_NUMBER: _ClassVar[int]
|
|
198
202
|
INPUT_FIELD_NUMBER: _ClassVar[int]
|
|
@@ -200,6 +204,7 @@ class ScheduleWorkflowRequest(_message.Message):
|
|
|
200
204
|
PARENT_STEP_RUN_ID_FIELD_NUMBER: _ClassVar[int]
|
|
201
205
|
CHILD_INDEX_FIELD_NUMBER: _ClassVar[int]
|
|
202
206
|
CHILD_KEY_FIELD_NUMBER: _ClassVar[int]
|
|
207
|
+
ADDITIONAL_METADATA_FIELD_NUMBER: _ClassVar[int]
|
|
203
208
|
name: str
|
|
204
209
|
schedules: _containers.RepeatedCompositeFieldContainer[_timestamp_pb2.Timestamp]
|
|
205
210
|
input: str
|
|
@@ -207,23 +212,34 @@ class ScheduleWorkflowRequest(_message.Message):
|
|
|
207
212
|
parent_step_run_id: str
|
|
208
213
|
child_index: int
|
|
209
214
|
child_key: str
|
|
210
|
-
|
|
215
|
+
additional_metadata: str
|
|
216
|
+
def __init__(self, name: _Optional[str] = ..., schedules: _Optional[_Iterable[_Union[_timestamp_pb2.Timestamp, _Mapping]]] = ..., input: _Optional[str] = ..., parent_id: _Optional[str] = ..., parent_step_run_id: _Optional[str] = ..., child_index: _Optional[int] = ..., child_key: _Optional[str] = ..., additional_metadata: _Optional[str] = ...) -> None: ...
|
|
217
|
+
|
|
218
|
+
class ScheduledWorkflow(_message.Message):
|
|
219
|
+
__slots__ = ("id", "trigger_at")
|
|
220
|
+
ID_FIELD_NUMBER: _ClassVar[int]
|
|
221
|
+
TRIGGER_AT_FIELD_NUMBER: _ClassVar[int]
|
|
222
|
+
id: str
|
|
223
|
+
trigger_at: _timestamp_pb2.Timestamp
|
|
224
|
+
def __init__(self, id: _Optional[str] = ..., trigger_at: _Optional[_Union[_timestamp_pb2.Timestamp, _Mapping]] = ...) -> None: ...
|
|
211
225
|
|
|
212
226
|
class WorkflowVersion(_message.Message):
|
|
213
|
-
__slots__ = ("id", "created_at", "updated_at", "version", "order", "workflow_id")
|
|
227
|
+
__slots__ = ("id", "created_at", "updated_at", "version", "order", "workflow_id", "scheduled_workflows")
|
|
214
228
|
ID_FIELD_NUMBER: _ClassVar[int]
|
|
215
229
|
CREATED_AT_FIELD_NUMBER: _ClassVar[int]
|
|
216
230
|
UPDATED_AT_FIELD_NUMBER: _ClassVar[int]
|
|
217
231
|
VERSION_FIELD_NUMBER: _ClassVar[int]
|
|
218
232
|
ORDER_FIELD_NUMBER: _ClassVar[int]
|
|
219
233
|
WORKFLOW_ID_FIELD_NUMBER: _ClassVar[int]
|
|
234
|
+
SCHEDULED_WORKFLOWS_FIELD_NUMBER: _ClassVar[int]
|
|
220
235
|
id: str
|
|
221
236
|
created_at: _timestamp_pb2.Timestamp
|
|
222
237
|
updated_at: _timestamp_pb2.Timestamp
|
|
223
238
|
version: str
|
|
224
239
|
order: int
|
|
225
240
|
workflow_id: str
|
|
226
|
-
|
|
241
|
+
scheduled_workflows: _containers.RepeatedCompositeFieldContainer[ScheduledWorkflow]
|
|
242
|
+
def __init__(self, id: _Optional[str] = ..., created_at: _Optional[_Union[_timestamp_pb2.Timestamp, _Mapping]] = ..., updated_at: _Optional[_Union[_timestamp_pb2.Timestamp, _Mapping]] = ..., version: _Optional[str] = ..., order: _Optional[int] = ..., workflow_id: _Optional[str] = ..., scheduled_workflows: _Optional[_Iterable[_Union[ScheduledWorkflow, _Mapping]]] = ...) -> None: ...
|
|
227
243
|
|
|
228
244
|
class WorkflowTriggerEventRef(_message.Message):
|
|
229
245
|
__slots__ = ("parent_id", "event_key")
|
hatchet_sdk/hatchet.py
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import asyncio
|
|
2
2
|
import logging
|
|
3
|
-
from typing import Any, Callable, Optional,
|
|
3
|
+
from typing import Any, Callable, Optional, Type, TypeVar, cast, get_type_hints
|
|
4
4
|
|
|
5
|
+
from pydantic import BaseModel
|
|
5
6
|
from typing_extensions import deprecated
|
|
6
7
|
|
|
7
8
|
from hatchet_sdk.clients.rest_client import RestApi
|
|
@@ -27,14 +28,17 @@ from .clients.events import EventClient
|
|
|
27
28
|
from .clients.run_event_listener import RunEventListenerClient
|
|
28
29
|
from .logger import logger
|
|
29
30
|
from .worker.worker import Worker
|
|
30
|
-
from .workflow import
|
|
31
|
+
from .workflow import (
|
|
32
|
+
ConcurrencyExpression,
|
|
33
|
+
WorkflowInterface,
|
|
34
|
+
WorkflowMeta,
|
|
35
|
+
WorkflowStepProtocol,
|
|
36
|
+
)
|
|
31
37
|
|
|
32
|
-
|
|
33
|
-
R = TypeVar("R")
|
|
38
|
+
T = TypeVar("T", bound=BaseModel)
|
|
34
39
|
|
|
35
40
|
|
|
36
|
-
|
|
37
|
-
def workflow( # type: ignore[no-untyped-def]
|
|
41
|
+
def workflow(
|
|
38
42
|
name: str = "",
|
|
39
43
|
on_events: list[str] | None = None,
|
|
40
44
|
on_crons: list[str] | None = None,
|
|
@@ -44,11 +48,12 @@ def workflow( # type: ignore[no-untyped-def]
|
|
|
44
48
|
sticky: StickyStrategy = None,
|
|
45
49
|
default_priority: int | None = None,
|
|
46
50
|
concurrency: ConcurrencyExpression | None = None,
|
|
47
|
-
|
|
51
|
+
input_validator: Type[T] | None = None,
|
|
52
|
+
) -> Callable[[Type[WorkflowInterface]], WorkflowMeta]:
|
|
48
53
|
on_events = on_events or []
|
|
49
54
|
on_crons = on_crons or []
|
|
50
55
|
|
|
51
|
-
def inner(cls:
|
|
56
|
+
def inner(cls: Type[WorkflowInterface]) -> WorkflowMeta:
|
|
52
57
|
cls.on_events = on_events
|
|
53
58
|
cls.on_crons = on_crons
|
|
54
59
|
cls.name = name or str(cls.__name__)
|
|
@@ -62,7 +67,8 @@ def workflow( # type: ignore[no-untyped-def]
|
|
|
62
67
|
# with WorkflowMeta as its metaclass
|
|
63
68
|
|
|
64
69
|
## TODO: Figure out how to type this metaclass correctly
|
|
65
|
-
|
|
70
|
+
cls.input_validator = input_validator
|
|
71
|
+
return WorkflowMeta(cls.name, cls.__bases__, dict(cls.__dict__))
|
|
66
72
|
|
|
67
73
|
return inner
|
|
68
74
|
|
|
@@ -74,10 +80,12 @@ def step(
|
|
|
74
80
|
retries: int = 0,
|
|
75
81
|
rate_limits: list[RateLimit] | None = None,
|
|
76
82
|
desired_worker_labels: dict[str, DesiredWorkerLabel] = {},
|
|
77
|
-
|
|
83
|
+
backoff_factor: float | None = None,
|
|
84
|
+
backoff_max_seconds: int | None = None,
|
|
85
|
+
) -> Callable[[WorkflowStepProtocol], WorkflowStepProtocol]:
|
|
78
86
|
parents = parents or []
|
|
79
87
|
|
|
80
|
-
def inner(func:
|
|
88
|
+
def inner(func: WorkflowStepProtocol) -> WorkflowStepProtocol:
|
|
81
89
|
limits = None
|
|
82
90
|
if rate_limits:
|
|
83
91
|
limits = [
|
|
@@ -85,18 +93,19 @@ def step(
|
|
|
85
93
|
for rate_limit in rate_limits or []
|
|
86
94
|
]
|
|
87
95
|
|
|
88
|
-
|
|
89
|
-
func.
|
|
90
|
-
func.
|
|
91
|
-
func.
|
|
92
|
-
func.
|
|
93
|
-
func.
|
|
96
|
+
func._step_name = name.lower() or str(func.__name__).lower()
|
|
97
|
+
func._step_parents = parents
|
|
98
|
+
func._step_timeout = timeout
|
|
99
|
+
func._step_retries = retries
|
|
100
|
+
func._step_rate_limits = limits
|
|
101
|
+
func._step_backoff_factor = backoff_factor
|
|
102
|
+
func._step_backoff_max_seconds = backoff_max_seconds
|
|
94
103
|
|
|
95
|
-
func._step_desired_worker_labels = {}
|
|
104
|
+
func._step_desired_worker_labels = {}
|
|
96
105
|
|
|
97
106
|
for key, d in desired_worker_labels.items():
|
|
98
107
|
value = d["value"] if "value" in d else None
|
|
99
|
-
func._step_desired_worker_labels[key] = DesiredWorkerLabels(
|
|
108
|
+
func._step_desired_worker_labels[key] = DesiredWorkerLabels(
|
|
100
109
|
strValue=str(value) if not isinstance(value, int) else None,
|
|
101
110
|
intValue=value if isinstance(value, int) else None,
|
|
102
111
|
required=d["required"] if "required" in d else None,
|
|
@@ -114,8 +123,10 @@ def on_failure_step(
|
|
|
114
123
|
timeout: str = "",
|
|
115
124
|
retries: int = 0,
|
|
116
125
|
rate_limits: list[RateLimit] | None = None,
|
|
117
|
-
|
|
118
|
-
|
|
126
|
+
backoff_factor: float | None = None,
|
|
127
|
+
backoff_max_seconds: int | None = None,
|
|
128
|
+
) -> Callable[[WorkflowStepProtocol], WorkflowStepProtocol]:
|
|
129
|
+
def inner(func: WorkflowStepProtocol) -> WorkflowStepProtocol:
|
|
119
130
|
limits = None
|
|
120
131
|
if rate_limits:
|
|
121
132
|
limits = [
|
|
@@ -123,11 +134,13 @@ def on_failure_step(
|
|
|
123
134
|
for rate_limit in rate_limits or []
|
|
124
135
|
]
|
|
125
136
|
|
|
126
|
-
|
|
127
|
-
func.
|
|
128
|
-
func.
|
|
129
|
-
func.
|
|
130
|
-
func.
|
|
137
|
+
func._on_failure_step_name = name.lower() or str(func.__name__).lower()
|
|
138
|
+
func._on_failure_step_timeout = timeout
|
|
139
|
+
func._on_failure_step_retries = retries
|
|
140
|
+
func._on_failure_step_rate_limits = limits
|
|
141
|
+
func._on_failure_step_backoff_factor = backoff_factor
|
|
142
|
+
func._on_failure_step_backoff_max_seconds = backoff_max_seconds
|
|
143
|
+
|
|
131
144
|
return func
|
|
132
145
|
|
|
133
146
|
return inner
|
|
@@ -137,12 +150,11 @@ def concurrency(
|
|
|
137
150
|
name: str = "",
|
|
138
151
|
max_runs: int = 1,
|
|
139
152
|
limit_strategy: ConcurrencyLimitStrategy = ConcurrencyLimitStrategy.CANCEL_IN_PROGRESS,
|
|
140
|
-
) -> Callable[[
|
|
141
|
-
def inner(func:
|
|
142
|
-
|
|
143
|
-
func.
|
|
144
|
-
func.
|
|
145
|
-
func._concurrency_limit_strategy = limit_strategy # type: ignore[attr-defined]
|
|
153
|
+
) -> Callable[[WorkflowStepProtocol], WorkflowStepProtocol]:
|
|
154
|
+
def inner(func: WorkflowStepProtocol) -> WorkflowStepProtocol:
|
|
155
|
+
func._concurrency_fn_name = name.lower() or str(func.__name__).lower()
|
|
156
|
+
func._concurrency_max_runs = max_runs
|
|
157
|
+
func._concurrency_limit_strategy = limit_strategy
|
|
146
158
|
|
|
147
159
|
return func
|
|
148
160
|
|
hatchet_sdk/utils/backoff.py
CHANGED
|
@@ -2,7 +2,7 @@ import asyncio
|
|
|
2
2
|
import random
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
async def exp_backoff_sleep(attempt: int, max_sleep_time: float = 5):
|
|
5
|
+
async def exp_backoff_sleep(attempt: int, max_sleep_time: float = 5) -> None:
|
|
6
6
|
base_time = 0.1 # starting sleep time in seconds (100 milliseconds)
|
|
7
7
|
jitter = random.uniform(0, base_time) # add random jitter
|
|
8
8
|
sleep_time = min(base_time * (2**attempt) + jitter, max_sleep_time)
|
|
@@ -2,7 +2,10 @@ from typing import Any
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
def flatten(xs: dict[str, Any], parent_key: str, separator: str) -> dict[str, Any]:
|
|
5
|
-
|
|
5
|
+
if not xs:
|
|
6
|
+
return {}
|
|
7
|
+
|
|
8
|
+
items: list[tuple[str, Any]] = []
|
|
6
9
|
|
|
7
10
|
for k, v in xs.items():
|
|
8
11
|
new_key = parent_key + separator + k if parent_key else k
|
hatchet_sdk/utils/tracing.py
CHANGED
|
@@ -6,9 +6,9 @@ from opentelemetry import trace
|
|
|
6
6
|
from opentelemetry.context import Context
|
|
7
7
|
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
|
|
8
8
|
from opentelemetry.sdk.resources import SERVICE_NAME, Resource
|
|
9
|
-
from opentelemetry.sdk.trace import
|
|
9
|
+
from opentelemetry.sdk.trace import TracerProvider
|
|
10
10
|
from opentelemetry.sdk.trace.export import BatchSpanProcessor
|
|
11
|
-
from opentelemetry.trace import NoOpTracerProvider
|
|
11
|
+
from opentelemetry.trace import NoOpTracerProvider, Tracer
|
|
12
12
|
from opentelemetry.trace.propagation.tracecontext import TraceContextTextMapPropagator
|
|
13
13
|
|
|
14
14
|
from hatchet_sdk.loader import ClientConfig
|
|
@@ -44,7 +44,7 @@ def create_tracer(config: ClientConfig) -> Tracer:
|
|
|
44
44
|
|
|
45
45
|
|
|
46
46
|
def create_carrier() -> dict[str, str]:
|
|
47
|
-
carrier = {}
|
|
47
|
+
carrier: dict[str, str] = {}
|
|
48
48
|
TraceContextTextMapPropagator().inject(carrier)
|
|
49
49
|
|
|
50
50
|
return carrier
|
|
@@ -59,7 +59,10 @@ def inject_carrier_into_metadata(
|
|
|
59
59
|
return metadata
|
|
60
60
|
|
|
61
61
|
|
|
62
|
-
def parse_carrier_from_metadata(metadata: dict[str, Any]) -> Context:
|
|
62
|
+
def parse_carrier_from_metadata(metadata: dict[str, Any] | None) -> Context | None:
|
|
63
|
+
if not metadata:
|
|
64
|
+
return None
|
|
65
|
+
|
|
63
66
|
return (
|
|
64
67
|
TraceContextTextMapPropagator().extract(_ctx)
|
|
65
68
|
if (_ctx := metadata.get(OTEL_CARRIER_KEY))
|
hatchet_sdk/v2/callable.py
CHANGED
|
@@ -87,15 +87,13 @@ class WorkerActionListenerProcess:
|
|
|
87
87
|
try:
|
|
88
88
|
self.dispatcher_client = new_dispatcher(self.config)
|
|
89
89
|
|
|
90
|
-
self.listener
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
_labels=self.labels,
|
|
98
|
-
)
|
|
90
|
+
self.listener = await self.dispatcher_client.get_action_listener(
|
|
91
|
+
GetActionListenerRequest(
|
|
92
|
+
worker_name=self.name,
|
|
93
|
+
services=["default"],
|
|
94
|
+
actions=self.actions,
|
|
95
|
+
max_runs=self.max_runs,
|
|
96
|
+
_labels=self.labels,
|
|
99
97
|
)
|
|
100
98
|
)
|
|
101
99
|
|
|
@@ -2,23 +2,28 @@ import asyncio
|
|
|
2
2
|
import logging
|
|
3
3
|
from dataclasses import dataclass, field
|
|
4
4
|
from multiprocessing import Queue
|
|
5
|
-
from typing import
|
|
5
|
+
from typing import Callable, TypeVar
|
|
6
6
|
|
|
7
|
+
from hatchet_sdk import Context
|
|
7
8
|
from hatchet_sdk.client import Client, new_client_raw
|
|
8
9
|
from hatchet_sdk.clients.dispatcher.action_listener import Action
|
|
9
10
|
from hatchet_sdk.loader import ClientConfig
|
|
10
11
|
from hatchet_sdk.logger import logger
|
|
12
|
+
from hatchet_sdk.utils.types import WorkflowValidator
|
|
11
13
|
from hatchet_sdk.worker.runner.runner import Runner
|
|
12
14
|
from hatchet_sdk.worker.runner.utils.capture_logs import capture_logs
|
|
13
15
|
|
|
14
16
|
STOP_LOOP = "STOP_LOOP"
|
|
15
17
|
|
|
18
|
+
T = TypeVar("T")
|
|
19
|
+
|
|
16
20
|
|
|
17
21
|
@dataclass
|
|
18
22
|
class WorkerActionRunLoopManager:
|
|
19
23
|
name: str
|
|
20
|
-
action_registry:
|
|
21
|
-
|
|
24
|
+
action_registry: dict[str, Callable[[Context], T]]
|
|
25
|
+
validator_registry: dict[str, WorkflowValidator]
|
|
26
|
+
max_runs: int | None
|
|
22
27
|
config: ClientConfig
|
|
23
28
|
action_queue: Queue
|
|
24
29
|
event_queue: Queue
|
|
@@ -48,29 +53,30 @@ class WorkerActionRunLoopManager:
|
|
|
48
53
|
self._async_start,
|
|
49
54
|
)(retry_count=retry_count)
|
|
50
55
|
|
|
51
|
-
async def _async_start(self, retry_count=1):
|
|
56
|
+
async def _async_start(self, retry_count: int = 1) -> None:
|
|
52
57
|
logger.info("starting runner...")
|
|
53
58
|
self.loop = asyncio.get_running_loop()
|
|
54
59
|
# needed for graceful termination
|
|
55
60
|
k = self.loop.create_task(self._start_action_loop())
|
|
56
61
|
await k
|
|
57
62
|
|
|
58
|
-
def cleanup(self):
|
|
63
|
+
def cleanup(self) -> None:
|
|
59
64
|
self.killing = True
|
|
60
65
|
|
|
61
66
|
self.action_queue.put(STOP_LOOP)
|
|
62
67
|
|
|
63
|
-
async def wait_for_tasks(self):
|
|
68
|
+
async def wait_for_tasks(self) -> None:
|
|
64
69
|
if self.runner:
|
|
65
70
|
await self.runner.wait_for_tasks()
|
|
66
71
|
|
|
67
|
-
async def _start_action_loop(self):
|
|
72
|
+
async def _start_action_loop(self) -> None:
|
|
68
73
|
self.runner = Runner(
|
|
69
74
|
self.name,
|
|
70
75
|
self.event_queue,
|
|
71
76
|
self.max_runs,
|
|
72
77
|
self.handle_kill,
|
|
73
78
|
self.action_registry,
|
|
79
|
+
self.validator_registry,
|
|
74
80
|
self.config,
|
|
75
81
|
self.labels,
|
|
76
82
|
)
|
|
@@ -88,7 +94,7 @@ class WorkerActionRunLoopManager:
|
|
|
88
94
|
async def _get_action(self):
|
|
89
95
|
return await self.loop.run_in_executor(None, self.action_queue.get)
|
|
90
96
|
|
|
91
|
-
async def exit_gracefully(self):
|
|
97
|
+
async def exit_gracefully(self) -> None:
|
|
92
98
|
if self.killing:
|
|
93
99
|
return
|
|
94
100
|
|
|
@@ -101,6 +107,6 @@ class WorkerActionRunLoopManager:
|
|
|
101
107
|
# task list.
|
|
102
108
|
await asyncio.sleep(1)
|
|
103
109
|
|
|
104
|
-
def exit_forcefully(self):
|
|
110
|
+
def exit_forcefully(self) -> None:
|
|
105
111
|
logger.info("forcefully exiting runner...")
|
|
106
112
|
self.cleanup()
|