Skip to content
This repository was archived by the owner on Feb 20, 2025. It is now read-only.

Commit 4008257

Browse files
committed
fix: optional declaration
1 parent 6d065ac commit 4008257

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

examples/simple/worker.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@
99

1010

1111
class MyWorkflow(BaseWorkflowImpl):
12-
declaration = hatchet.declare_workflow(
13-
name="foobar",
14-
on_events=["user:create"],
15-
)
16-
1712
@hatchet.step(timeout="11s", retries=3)
1813
def step1(self, context: Context) -> dict[str, str]:
1914
print("executed step1")

hatchet_sdk/v2/workflows.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,14 @@ async def acall(self, ctx: Context) -> R:
166166

167167

168168
class WorkflowDeclaration(Generic[TWorkflowInput]):
169-
def __init__(self, config: WorkflowConfig, hatchet: "Hatchet"):
169+
def __init__(self, config: WorkflowConfig, hatchet: Union["Hatchet", None]):
170170
self.config = config
171171
self.hatchet = hatchet
172172

173173
def run(self, input: TWorkflowInput | None = None) -> Any:
174+
if not self.hatchet:
175+
raise ValueError("Hatchet client is not initialized.")
176+
174177
return self.hatchet.admin.run_workflow(
175178
workflow_name=self.config.name, input=input.model_dump() if input else {}
176179
)
@@ -183,7 +186,9 @@ class BaseWorkflowImpl:
183186
Configuration is passed to the workflow implementation via the `config` attribute.
184187
"""
185188

186-
declaration: WorkflowDeclaration
189+
declaration: WorkflowDeclaration = WorkflowDeclaration(
190+
config=WorkflowConfig(), hatchet=None
191+
)
187192

188193
def get_service_name(self, namespace: str) -> str:
189194
return f"{namespace}{self.config.name.lower()}"

0 commit comments

Comments
 (0)