-
Notifications
You must be signed in to change notification settings - Fork 110
Expand file tree
/
Copy pathworkflow.py
More file actions
29 lines (22 loc) · 915 Bytes
/
Copy pathworkflow.py
File metadata and controls
29 lines (22 loc) · 915 Bytes
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
from datetime import timedelta
from temporalio import workflow
@workflow.defn
class BasicPauseWorkflow:
"""A loop that logs progress and sleeps on a timer each iteration.
While the workflow is paused, no workflow tasks are dispatched, so the
timer does not advance and the iteration count stops moving. Unpausing
lets it resume from where it left off.
"""
def __init__(self) -> None:
self._completed = 0
@workflow.run
async def run(self, iterations: int) -> int:
for i in range(iterations):
workflow.logger.info("Starting iteration %d of %d", i + 1, iterations)
await workflow.sleep(timedelta(seconds=3))
self._completed += 1
workflow.logger.info("Completed iteration %d of %d", i + 1, iterations)
return self._completed
@workflow.query
def completed(self) -> int:
return self._completed