forked from naveenachyuta/naf-temporal-2025
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworkflows.py
More file actions
65 lines (54 loc) · 2.13 KB
/
Copy pathworkflows.py
File metadata and controls
65 lines (54 loc) · 2.13 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
61
62
63
64
65
from datetime import timedelta
from temporalio import workflow
from temporalio.common import RetryPolicy
from temporalio.exceptions import ActivityError, ApplicationError
with workflow.unsafe.imports_passed_through():
from activities import DeviceActivities
from shared import DeviceDetails
@workflow.defn
class ConfigPush:
@workflow.run
async def run(self, device_details: DeviceDetails) -> str:
codeword = ""
retry_policy = RetryPolicy(
maximum_attempts=3,
maximum_interval=timedelta(seconds=5),
non_retryable_error_types=["InterfaceStatusError"],
)
post_check_retry_policy = RetryPolicy(
maximum_attempts=3,
initial_interval=timedelta(seconds=10),
backoff_coefficient=2.0,
)
try:
# Check interface status
word = await workflow.execute_activity_method(
DeviceActivities.check_intf_status,
device_details,
start_to_close_timeout=timedelta(seconds=10),
retry_policy=retry_policy,
)
except ActivityError:
raise ApplicationError("Interface status check failed", "InterfaceStatusError")
codeword += word
try:
word = await workflow.execute_activity_method(
DeviceActivities.push_config,
device_details,
start_to_close_timeout=timedelta(seconds=10),
retry_policy=retry_policy,
)
except ActivityError:
raise ApplicationError("Config push failed", "ConfigPushError")
codeword += word
try:
word = await workflow.execute_activity_method(
DeviceActivities.verify_bgp_state,
device_details,
start_to_close_timeout=timedelta(seconds=10),
retry_policy=post_check_retry_policy,
)
except ActivityError:
raise ApplicationError("BGP state verification failed", "BGPStateVerificationError")
codeword += word
return f"Config push successful. Codeword is {codeword}"