-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix: More OTel Cleanup (#319) * feat: factor our helpers * chore: bump version * fix: replace none-default * fix: auto-create parent * feat: docs * fix: doc format * fix: example * feat: use global tracer if none provided * fix: docs * Fix: Bump min `celpy` version (#320) * fix: bump min celpy version * chore: ver * Feat: Sync spawn methods + fixing `sync_result` (#321) * feat: add sync spawn method * feat: example * fix: sync workflow run + sync_result * fix: examples * fix: lint * feat: bulk spawn * chore: ver * fix: test * fix: lint * Feat: Killing sync threads (#323) * feat: thread killing * fix: rm events * fix: lint * fix: cruft * fix: async sleep * feat: flag for enabling force killing threads
- Loading branch information
Showing
14 changed files
with
326 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import pytest | ||
|
||
from hatchet_sdk import Hatchet, Worker | ||
|
||
|
||
@pytest.mark.parametrize("worker", ["fanout_sync"], indirect=True) | ||
def test_run(hatchet: Hatchet, worker: Worker) -> None: | ||
run = hatchet.admin.run_workflow("SyncFanoutParent", {"n": 2}) | ||
result = run.sync_result() | ||
assert len(result["spawn"]["results"]) == 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import asyncio | ||
|
||
from dotenv import load_dotenv | ||
|
||
from hatchet_sdk import new_client | ||
|
||
|
||
async def main() -> None: | ||
load_dotenv() | ||
hatchet = new_client() | ||
|
||
hatchet.admin.run_workflow( | ||
"SyncFanoutParent", | ||
{"test": "test"}, | ||
options={"additional_metadata": {"hello": "moon"}}, | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
asyncio.run(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
from typing import Any | ||
|
||
from dotenv import load_dotenv | ||
|
||
from hatchet_sdk import Context, Hatchet | ||
from hatchet_sdk.workflow_run import WorkflowRunRef | ||
|
||
load_dotenv() | ||
|
||
hatchet = Hatchet(debug=True) | ||
|
||
|
||
@hatchet.workflow(on_events=["parent:create"]) | ||
class SyncFanoutParent: | ||
@hatchet.step(timeout="5m") | ||
def spawn(self, context: Context) -> dict[str, Any]: | ||
print("spawning child") | ||
|
||
n = context.workflow_input().get("n", 5) | ||
|
||
runs = context.spawn_workflows( | ||
[ | ||
{ | ||
"workflow_name": "SyncFanoutChild", | ||
"input": {"a": str(i)}, | ||
"key": f"child{i}", | ||
"options": {"additional_metadata": {"hello": "earth"}}, | ||
} | ||
for i in range(n) | ||
] | ||
) | ||
|
||
results = [r.sync_result() for r in runs] | ||
|
||
print(f"results {results}") | ||
|
||
return {"results": results} | ||
|
||
|
||
@hatchet.workflow(on_events=["child:create"]) | ||
class SyncFanoutChild: | ||
@hatchet.step() | ||
def process(self, context: Context) -> dict[str, str]: | ||
return {"status": "success " + context.workflow_input()["a"]} | ||
|
||
|
||
def main() -> None: | ||
worker = hatchet.worker("sync-fanout-worker", max_runs=40) | ||
worker.register_workflow(SyncFanoutParent()) | ||
worker.register_workflow(SyncFanoutChild()) | ||
worker.start() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.