forked from temporalio/samples-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathactivities.py
36 lines (28 loc) · 1.04 KB
/
activities.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
import asyncio
import time
from dataclasses import dataclass
from temporalio import activity
from polling.test_service import TestService
@dataclass
class ComposeGreetingInput:
greeting: str
name: str
@activity.defn
async def compose_greeting(input: ComposeGreetingInput) -> str:
test_service = TestService()
while True:
try:
try:
result = await test_service.get_service_result(input)
activity.logger.info(f"Exiting activity ${result}")
return result
except Exception as e:
# swallow exception since service is down
activity.logger.debug("Failed, trying again shortly", exc_info=True)
activity.heartbeat("Invoking activity")
await asyncio.sleep(1)
except asyncio.CancelledError:
# activity was either cancelled or workflow was completed or worker shut down
# if you need to clean up you can catch this.
# Here we are just reraising the exception
raise