19
19
import time
20
20
21
21
from google .api_core .exceptions import Aborted
22
+ from google .api_core .exceptions import NotFound
22
23
from google .api_core .exceptions import ServiceUnavailable
23
24
from google .cloud import monitoring_v3
24
25
import google .protobuf .json_format
@@ -44,7 +45,7 @@ def retry_if_aborted(exception):
44
45
def delay_on_aborted (err , * args ):
45
46
if retry_if_aborted (err [1 ]):
46
47
# add randomness for avoiding continuous conflict
47
- time .sleep (2 + (random .randint (0 , 9 ) * 0.1 ))
48
+ time .sleep (5 + (random .randint (0 , 9 ) * 0.1 ))
48
49
return True
49
50
return False
50
51
@@ -90,11 +91,18 @@ def __exit__(self, type, value, traceback):
90
91
@retry (wait_exponential_multiplier = 1000 , wait_exponential_max = 10000 ,
91
92
stop_max_attempt_number = 5 , retry_on_exception = retry_if_aborted )
92
93
def teardown ():
93
- self .alert_policy_client .delete_alert_policy (
94
- self .alert_policy .name )
95
- if self .notification_channel .name :
96
- self .notification_channel_client .delete_notification_channel (
97
- self .notification_channel .name )
94
+ try :
95
+ self .alert_policy_client .delete_alert_policy (
96
+ self .alert_policy .name )
97
+ except NotFound :
98
+ print ("Ignored NotFound when deleting a policy." )
99
+ try :
100
+ if self .notification_channel .name :
101
+ self .notification_channel_client \
102
+ .delete_notification_channel (
103
+ self .notification_channel .name )
104
+ except NotFound :
105
+ print ("Ignored NotFound when deleting a channel." )
98
106
teardown ()
99
107
100
108
0 commit comments