mirror of
https://github.com/hatchet-dev/hatchet.git
synced 2025-12-31 13:49:48 -06:00
* api changes * doc changes * move docs * generated * generate * pkg * backmerge main * revert to main * revert main * race? * remove go tests
43 lines
966 B
Python
43 lines
966 B
Python
import asyncio
|
|
from contextlib import suppress
|
|
|
|
from hatchet_sdk import Context, EmptyModel, Hatchet
|
|
|
|
hatchet = Hatchet(debug=True)
|
|
|
|
existing_loop_worker = hatchet.workflow(name="WorkerExistingLoopWorkflow")
|
|
|
|
|
|
@existing_loop_worker.task()
|
|
async def task(input: EmptyModel, ctx: Context) -> dict[str, str]:
|
|
print("started")
|
|
await asyncio.sleep(10)
|
|
print("finished")
|
|
return {"result": "returned result"}
|
|
|
|
|
|
async def async_main() -> None:
|
|
worker = None
|
|
try:
|
|
worker = hatchet.worker(
|
|
"test-worker", slots=1, workflows=[existing_loop_worker]
|
|
)
|
|
worker.start()
|
|
|
|
ref = existing_loop_worker.run_no_wait()
|
|
print(await ref.aio_result())
|
|
while True:
|
|
await asyncio.sleep(1)
|
|
finally:
|
|
if worker:
|
|
await worker.exit_gracefully()
|
|
|
|
|
|
def main() -> None:
|
|
with suppress(KeyboardInterrupt):
|
|
asyncio.run(async_main())
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|