-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathworkflows.py
30 lines (26 loc) · 1.1 KB
/
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
29
30
from datetime import timedelta
from temporalio import workflow
with workflow.unsafe.imports_passed_through():
from trio_async.activities import say_hello_activity_async, say_hello_activity_sync
@workflow.defn
class SayHelloWorkflow:
@workflow.run
async def run(self, name: str) -> list[str]:
# Workflows don't use default asyncio event loop or Trio, they use a
# custom event loop. Therefore Trio primitives should never be used in a
# workflow, only asyncio helpers (which delegate to the custom loop).
return [
# That these are two different activities for async or sync means
# nothing to the workflow, we just have both to demonstrate the
# activity side
await workflow.execute_activity(
say_hello_activity_async,
name,
start_to_close_timeout=timedelta(minutes=5),
),
await workflow.execute_activity(
say_hello_activity_sync,
name,
start_to_close_timeout=timedelta(minutes=5),
),
]