mirror of
https://github.com/hatchet-dev/hatchet.git
synced 2025-12-30 21:29:44 -06:00
Fe overhaul docs (#1640)
* api changes * doc changes * move docs * generated * generate * pkg * backmerge main * revert to main * revert main * race? * remove go tests
This commit is contained in:
42
examples/python/worker_existing_loop/worker.py
Normal file
42
examples/python/worker_existing_loop/worker.py
Normal file
@@ -0,0 +1,42 @@
|
||||
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()
|
||||
Reference in New Issue
Block a user