forked from temporalio/samples-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
workflows.py
28 lines (21 loc) · 883 Bytes
/
workflows.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
from datetime import timedelta
from temporalio import workflow
with workflow.unsafe.imports_passed_through():
from context_propagation.activities import say_hello_activity
from context_propagation.shared import user_id
@workflow.defn
class SayHelloWorkflow:
def __init__(self) -> None:
self._complete = False
@workflow.run
async def run(self, name: str) -> str:
workflow.logger.info(f"Workflow called by user {user_id.get()}")
# Wait for signal then run activity
await workflow.wait_condition(lambda: self._complete)
return await workflow.execute_activity(
say_hello_activity, name, start_to_close_timeout=timedelta(minutes=5)
)
@workflow.signal
async def signal_complete(self) -> None:
workflow.logger.info(f"Signal called by user {user_id.get()}")
self._complete = True