forked from temporalio/sdk-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexternal_stack_trace.py
More file actions
60 lines (48 loc) · 1.59 KB
/
Copy pathexternal_stack_trace.py
File metadata and controls
60 lines (48 loc) · 1.59 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
"""
File used to test external filenames with __enhanced_stack_trace.
"""
import asyncio
from datetime import timedelta
from temporalio import activity, workflow
from tests.helpers.external_coroutine import never_completing_coroutine, wait_on_timer
@activity.defn
async def external_wait_cancel() -> str:
try:
if activity.info().is_local:
await asyncio.sleep(1000)
else:
while True:
await asyncio.sleep(0.3)
activity.heartbeat()
return "Manually stopped"
except asyncio.CancelledError:
return "Got cancelled error, cancelled? " + str(activity.is_cancelled())
@workflow.defn
class ExternalStackTraceWorkflow:
def __init__(self) -> None:
self._status = ["created"]
@workflow.run
async def run(self) -> None:
# Start several tasks
self._status = ["spawning"]
awaitables = [
asyncio.sleep(1000),
workflow.execute_activity(
external_wait_cancel, schedule_to_close_timeout=timedelta(seconds=1000)
),
never_completing_coroutine(self._status),
]
await workflow.wait([asyncio.create_task(v) for v in awaitables])
@workflow.query
def status(self) -> str:
return self._status[0]
@workflow.defn
class MultiFileStackTraceWorkflow:
def __init__(self) -> None:
self._status = ["created"]
@workflow.run
async def run_multifile_workflow(self) -> None:
await wait_on_timer(self._status)
@workflow.query
def status(self) -> str:
return self._status[0]