-
Notifications
You must be signed in to change notification settings - Fork 95
Expand file tree
/
Copy pathtest_service.py
More file actions
30 lines (23 loc) · 915 Bytes
/
test_service.py
File metadata and controls
30 lines (23 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
30
from dataclasses import dataclass
from typing import Counter
from temporalio import activity
from temporalio.exceptions import ApplicationError, ApplicationErrorCategory
attempts = Counter[str | None]()
ERROR_ATTEMPTS = 5
@dataclass
class ComposeGreetingInput:
greeting: str
name: str
async def get_service_result(input):
workflow_id = activity.info().workflow_id
attempts[workflow_id] += 1
print(f"Attempt {attempts[workflow_id]} of {ERROR_ATTEMPTS} to invoke service")
if attempts[workflow_id] == ERROR_ATTEMPTS:
return f"{input.greeting}, {input.name}!"
raise ApplicationError(
message="service is down",
# Set the error as BENIGN to indicate it is an expected error.
# BENIGN errors have activity failure logs downgraded to DEBUG level
# and do not emit activity failure metrics.
category=ApplicationErrorCategory.BENIGN,
)