@@ -88,7 +88,7 @@ def raise_on_error(r: Optional[Response], verb="???", **kwargs):
88
88
class ResilientSession (Session ):
89
89
"""This class is supposed to retry requests that do return temporary errors.
90
90
91
- At this moment it supports: 502, 503, 504
91
+ At this moment it supports: 429
92
92
"""
93
93
94
94
def __init__ (self , timeout = None ):
@@ -113,11 +113,14 @@ def __recoverable(
113
113
f"Got ConnectionError [{ response } ] errno:{ response .errno } on { request } { url } \n { vars (response )} \n { response .__dict__ } "
114
114
)
115
115
if isinstance (response , Response ):
116
- if response .status_code in [502 , 503 , 504 , 401 ]:
117
- # 401 UNAUTHORIZED still randomly returned by Atlassian Cloud as of 2017-01-16
116
+ if response .status_code in [429 ]:
117
+ rate_limit_remaining = response . headers [ "X-RateLimit-Remaining" ]
118
118
msg = f"{ response .status_code } { response .reason } "
119
- # 2019-07-25: Disabled recovery for codes above^
120
- return False
119
+ logging .warning (
120
+ f"""Request rate limited by Jira: number of tokens remaining { rate_limit_remaining } . Consider adding exemption for the user as explained in
121
+ https://confluence.atlassian.com/adminjiraserver/improving-instance-stability-with-rate-limiting-983794911.html
122
+ """
123
+ )
121
124
elif not (
122
125
response .status_code == 200
123
126
and len (response .content ) == 0
@@ -128,7 +131,7 @@ def __recoverable(
128
131
else :
129
132
msg = "Atlassian's bug https://jira.atlassian.com/browse/JRA-41559"
130
133
131
- # Exponential backoff with full jitter .
134
+ # Exponential backoff with full jijitter .
132
135
delay = min (self .max_retry_delay , 10 * 2 ** counter ) * random .random ()
133
136
logging .warning (
134
137
"Got recoverable error from %s %s, will retry [%s/%s] in %ss. Err: %s"
@@ -137,6 +140,7 @@ def __recoverable(
137
140
if isinstance (response , Response ):
138
141
logging .debug ("response.headers: %s" , response .headers )
139
142
logging .debug ("response.body: %s" , response .content )
143
+ logging .debug (msg )
140
144
time .sleep (delay )
141
145
return True
142
146
0 commit comments