mirror of
https://github.com/hatchet-dev/hatchet.git
synced 2025-12-30 13:19:44 -06:00
Docs: Dataclasses (#2488)
* feat: dataclass docs * fix: add min version
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
from examples.dataclasses.worker import Input, say_hello
|
||||
|
||||
# > Triggering a task
|
||||
say_hello.run(input=Input(name="Hatchet"))
|
||||
|
||||
@@ -4,6 +4,7 @@ from typing import Literal
|
||||
from hatchet_sdk import Context, EmptyModel, Hatchet
|
||||
|
||||
|
||||
# > Dataclasses
|
||||
@dataclass
|
||||
class Input:
|
||||
name: str
|
||||
@@ -14,14 +15,19 @@ class Output:
|
||||
message: str
|
||||
|
||||
|
||||
|
||||
|
||||
hatchet = Hatchet(debug=True)
|
||||
|
||||
|
||||
# > Task using dataclasses
|
||||
@hatchet.task(input_validator=Input)
|
||||
def say_hello(input: Input, ctx: Context) -> Output:
|
||||
return Output(message=f"Hello, {input.name}!")
|
||||
|
||||
|
||||
|
||||
|
||||
def main() -> None:
|
||||
worker = hatchet.worker("test-worker", workflows=[say_hello])
|
||||
worker.start()
|
||||
|
||||
Reference in New Issue
Block a user