@@ -65,31 +65,23 @@ def _send_data_to_service_callback_api(self, data, service_callback_url, token,
65
65
data = json .dumps (data ),
66
66
headers = {
67
67
"Content-Type" : "application/json" ,
68
- "Authorization" : "Bearer {}" . format ( token ) ,
68
+ "Authorization" : f "Bearer { token } " ,
69
69
},
70
70
timeout = 5 ,
71
71
)
72
72
current_app .logger .info (
73
- "{} sending {} to {}, response {}" .format (
74
- function_name ,
75
- notification_id ,
76
- service_callback_url ,
77
- response .status_code ,
78
- )
73
+ f"{ function_name } sending { notification_id } to { service_callback_url } , response { response .status_code } "
79
74
)
80
75
response .raise_for_status ()
81
76
except RequestException as e :
82
77
current_app .logger .warning (
83
- "{} request failed for notification_id: {} and url: {}. exc: {}" .format (
84
- function_name , notification_id , service_callback_url , e
85
- )
78
+ f"{ function_name } request failed for notification_id: { notification_id } and url: { service_callback_url } . exc: { e } "
86
79
)
87
- if not isinstance (e , HTTPError ) or e .response .status_code >= 500 :
80
+ # Retry if the response status code is server-side or 429 (too many requests).
81
+ if not isinstance (e , HTTPError ) or e .response .status_code >= 500 or e .response .status_code == 429 :
88
82
try :
89
83
self .retry (queue = QueueNames .CALLBACKS_RETRY )
90
84
except self .MaxRetriesExceededError :
91
85
current_app .logger .warning (
92
- "Retry: {} has retried the max num of times for callback url {} and notification_id: {}" .format (
93
- function_name , service_callback_url , notification_id
94
- )
86
+ "Retry: {function_name} has retried the max num of times for callback url {service_callback_url} and notification_id: {notification_id}"
95
87
)
0 commit comments