File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ from hatchet_sdk import Hatchet
2+ from dotenv import load_dotenv
3+
4+ load_dotenv ()
5+
6+ # Create a Hatchet instance that will be shared across all workflows
7+ hatchet = Hatchet ()
Original file line number Diff line number Diff line change 1+ from .hatchet import hatchet
2+ from .simple import SimpleWorkflow
3+
4+ # This is the entry point for the Hatchet worker process
5+
6+
7+ def start ():
8+ worker = hatchet .worker ('example-worker' )
9+
10+ # Instantiate the workflow and Register the workflow with the worker
11+ simple = SimpleWorkflow ()
12+ worker .register_workflow (simple )
13+
14+ # Start the worker and begin listening for events
15+ worker .start ()
Original file line number Diff line number Diff line change 1+ [tool .poetry ]
2+ name = " src"
3+ version = " 0.0.0"
4+ description = " Easily run background tasks in FastAPI with Hatchet"
5+ authors = []
6+ readme = " README.md"
7+
8+ [tool .poetry .scripts ]
9+ api = " src.api.main:start"
10+ hatchet = " src.workflows.main:start"
11+
12+ [tool .poetry .dependencies ]
13+ python = " ^3.8"
14+ python-dotenv = " ^1.0.0"
15+ hatchet-sdk = " ^0.9.4"
16+ uvicorn = {extras = [" standard" ], version = " ^0.27.0" }
17+ fastapi = " ^0.109.0"
18+ beautifulsoup4 = " ^4.12.3"
19+ requests = " ^2.31.0"
20+ urllib3 = " 1.26.15"
21+
22+ [build-system ]
23+ requires = [" poetry-core" ]
24+ build-backend = " poetry.core.masonry.api"
25+
Original file line number Diff line number Diff line change 1+ from .hatchet import hatchet
2+ from hatchet_sdk import Context
3+
4+ # This is a simple example of a workflow that has 3 steps.
5+ # The workflow is declared decorated with `@hatchet_workflow` and the steps are declared with `@hatchet_step`.
6+
7+
8+ @hatchet .workflow (on_events = ["simple:create" ])
9+ class SimpleWorkflow :
10+
11+ @hatchet .step ()
12+ def step1 (self , context : Context ):
13+
14+ # The context object is passed to each step and contains the input data for the workflow.
15+ messages = context .workflow_input ()['request' ]['messages' ]
16+ print ("> starting step1" , messages )
17+ return {"status" : "thinking" }
18+
19+ @hatchet .step (parents = ["step1" ])
20+ def step2 (self , context : Context ):
21+ print ("starting step2" )
22+ return {"status" : "writing a response" }
23+
24+ @hatchet .step (parents = ["step2" ], timeout = '5m' )
25+ def step3 (self , context : Context ):
26+ messages = context .workflow_input ()['request' ]['messages' ]
27+ return {"complete" : "true" , "status" : "idle" , "message" : "response from step3" }
You can’t perform that action at this time.
0 commit comments