Files
hatchet/sdks/python/examples/streaming/worker.py
Matt Kaye 8172d59f84 [Python] Fix: Misc. Python Bugs (#1451)
* fix: stop trying to parse payloads back from json

* feat: streaming example

* feat: aio output

* fix: lint

* feat: sync and async examples

* fix: small issues

* fix: one more small thing

* chore: version

* fix: lint

* fix: add sleeps

* feat: factor out run_async_from_sync

* Revert "feat: factor out run_async_from_sync"

This reverts commit fb37395913.

* fix: schedule trigger namespace issue

* fix: log error if action payload fails to decode but don't raise out of listener
2025-03-31 13:47:34 -04:00

28 lines
532 B
Python

import asyncio
from hatchet_sdk import Context, EmptyModel, Hatchet
hatchet = Hatchet(debug=True)
# ❓ Streaming
streaming_workflow = hatchet.workflow(name="StreamingWorkflow")
@streaming_workflow.task()
async def step1(input: EmptyModel, ctx: Context) -> None:
for i in range(10):
await asyncio.sleep(1)
ctx.put_stream(f"Processing {i}")
def main() -> None:
worker = hatchet.worker("test-worker", workflows=[streaming_workflow])
worker.start()
# ‼️
if __name__ == "__main__":
main()