File tree Expand file tree Collapse file tree 3 files changed +29
-1
lines changed Expand file tree Collapse file tree 3 files changed +29
-1
lines changed Original file line number Diff line number Diff line change 20
20
ServiceHealth = dict [str , bool ]
21
21
22
22
23
- def instrument (prefix : str , exceptions : Sequence [Type [Exception ]]):
23
+ def instrument (prefix : str , exceptions : Sequence [Type [Exception ]], ** backoff_params ):
24
24
"""This decorator wraps a function such that it increments a counter every
25
25
time it is called and times its execution. It retries the function if the
26
26
specified exceptions are raised.
@@ -32,6 +32,7 @@ def decorator(func):
32
32
backoff .expo ,
33
33
exceptions ,
34
34
max_tries = settings .max_retries + 1 ,
35
+ ** backoff_params ,
35
36
)
36
37
def wrapper (* args , ** kwargs ):
37
38
# Increment the call counter.
Original file line number Diff line number Diff line change 30
30
31
31
JIRA_DESCRIPTION_CHAR_LIMIT = 32767
32
32
33
+
34
+ def fatal_code (e ):
35
+ # Do not retry 4XX errors, mark them as fatal.
36
+ try :
37
+ return 400 <= e .response .status_code < 500
38
+ except AttributeError :
39
+ # `ApiError` or `ConnectionError` won't have response attribute.
40
+ return False
41
+
42
+
33
43
instrumented_method = instrument (
34
44
prefix = "jira" ,
35
45
exceptions = (
36
46
atlassian_errors .ApiError ,
37
47
requests_exceptions .RequestException ,
38
48
),
49
+ giveup = fatal_code ,
39
50
)
40
51
41
52
Original file line number Diff line number Diff line change @@ -87,6 +87,22 @@ def test_jira_retries_failing_connections_in_health_check(
87
87
assert len (mocked_responses .calls ) == 4
88
88
89
89
90
+ @pytest .mark .no_mocked_jira
91
+ def test_jira_does_not_retry_4XX (mocked_responses , context_create_example ):
92
+ url = f"{ get_settings ().jira_base_url } rest/api/2/issue"
93
+ mocked_responses .add (
94
+ responses .POST ,
95
+ url ,
96
+ json = {},
97
+ status = 400 ,
98
+ )
99
+
100
+ with pytest .raises (requests .HTTPError ):
101
+ jira .create_jira_issue (context = context_create_example , description = "" )
102
+
103
+ assert len (mocked_responses .calls ) == 1
104
+
105
+
90
106
@pytest .mark .parametrize (
91
107
"jira_components, project_components, expected_result" ,
92
108
[
You can’t perform that action at this time.
0 commit comments