Blocked event loop blog post (#1775)

* feat: snippets

* feat: first couple paragraphs

* feat: flesh out hatchet examples

* fix: one more

* feat: log view

* fix: cleanup

* feat: another section

* fix: fmt

* feat: debugging section

* fix: proofread

* fix: lint

* chore: gen

* fix: copilot

* fix: copilot

* feat: add blog post link

* fix: feedback

* chore: sdk ver

* chore: gen

* fix: ugh
This commit is contained in:
Matt Kaye
2025-05-27 14:07:34 -04:00
committed by GitHub
parent 521c5f430f
commit f9d3d508ca
36 changed files with 1609 additions and 45 deletions

View File

@@ -0,0 +1,41 @@
import pytest
from examples.simple.worker import simple, simple_durable
from hatchet_sdk import EmptyModel
from hatchet_sdk.runnables.standalone import Standalone
@pytest.mark.parametrize("task", [simple, simple_durable])
@pytest.mark.asyncio(loop_scope="session")
async def test_simple_workflow_running_options(
task: Standalone[EmptyModel, dict[str, str]]
) -> None:
x1 = task.run()
x2 = await task.aio_run()
x3 = task.run_many([task.create_bulk_run_item()])[0]
x4 = (await task.aio_run_many([task.create_bulk_run_item()]))[0]
x5 = task.run_no_wait().result()
x6 = (await task.aio_run_no_wait()).result()
x7 = [x.result() for x in task.run_many_no_wait([task.create_bulk_run_item()])][0]
x8 = [
x.result()
for x in await task.aio_run_many_no_wait([task.create_bulk_run_item()])
][0]
x9 = await task.run_no_wait().aio_result()
x10 = await (await task.aio_run_no_wait()).aio_result()
x11 = [
await x.aio_result()
for x in task.run_many_no_wait([task.create_bulk_run_item()])
][0]
x12 = [
await x.aio_result()
for x in await task.aio_run_many_no_wait([task.create_bulk_run_item()])
][0]
assert all(
x == {"result": "Hello, world!"}
for x in [x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12]
)

View File

@@ -1,3 +1,3 @@
from examples.simple.worker import step1
from examples.simple.worker import simple
step1.run()
simple.run()

View File

@@ -5,13 +5,18 @@ from hatchet_sdk import Context, EmptyModel, Hatchet
hatchet = Hatchet(debug=True)
@hatchet.task(name="SimpleWorkflow")
def step1(input: EmptyModel, ctx: Context) -> None:
print("executed step1")
@hatchet.task()
def simple(input: EmptyModel, ctx: Context) -> dict[str, str]:
return {"result": "Hello, world!"}
@hatchet.durable_task()
def simple_durable(input: EmptyModel, ctx: Context) -> dict[str, str]:
return {"result": "Hello, world!"}
def main() -> None:
worker = hatchet.worker("test-worker", slots=1, workflows=[step1])
worker = hatchet.worker("test-worker", workflows=[simple, simple_durable])
worker.start()