forked from temporalio/samples-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hello_continue_as_new.py
46 lines (36 loc) · 1.22 KB
/
hello_continue_as_new.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import asyncio
import logging
from temporalio import workflow
from temporalio.client import Client
from temporalio.worker import Worker
@workflow.defn
class LoopingWorkflow:
@workflow.run
async def run(self, iteration: int) -> None:
if iteration == 10:
return
workflow.logger.info("Running workflow iteration %s", iteration)
await asyncio.sleep(1)
workflow.continue_as_new(iteration + 1)
async def main():
# Enable logging for this sample
logging.basicConfig(level=logging.INFO)
# Start client
client = await Client.connect("localhost:7233")
# Run a worker for the workflow
async with Worker(
client,
task_queue="hello-continue-as-new-task-queue",
workflows=[LoopingWorkflow],
):
# While the worker is running, use the client to run the workflow. Note,
# in many production setups, the client would be in a completely
# separate process from the worker.
await client.execute_workflow(
LoopingWorkflow.run,
0,
id="hello-continue-as-new-workflow-id",
task_queue="hello-continue-as-new-task-queue",
)
if __name__ == "__main__":
asyncio.run(main())