mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-02 09:26:08 -05:00
WIP - adding request timeout
This commit is contained in:
@@ -55,7 +55,8 @@ def make_request(notification_type, provider, data, headers):
|
|||||||
"POST",
|
"POST",
|
||||||
api_call,
|
api_call,
|
||||||
headers=headers,
|
headers=headers,
|
||||||
data=data
|
data=data,
|
||||||
|
timeout=5
|
||||||
)
|
)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
except RequestException as e:
|
except RequestException as e:
|
||||||
|
|||||||
@@ -97,7 +97,8 @@ class FiretextClient(SmsClient):
|
|||||||
response = request(
|
response = request(
|
||||||
"POST",
|
"POST",
|
||||||
self.url,
|
self.url,
|
||||||
data=data
|
data=data,
|
||||||
|
timeout=60
|
||||||
)
|
)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import json
|
import json
|
||||||
from monotonic import monotonic
|
from monotonic import monotonic
|
||||||
from requests import (request, RequestException)
|
from requests import (request, RequestException)
|
||||||
|
from requests.exceptions import HTTPError
|
||||||
from app.clients import (STATISTICS_DELIVERED, STATISTICS_FAILURE)
|
from app.clients import (STATISTICS_DELIVERED, STATISTICS_FAILURE)
|
||||||
from app.clients.sms import (SmsClient, SmsClientResponseException)
|
from app.clients.sms import (SmsClient, SmsClientResponseException)
|
||||||
|
|
||||||
@@ -104,7 +104,8 @@ class MMGClient(SmsClient):
|
|||||||
headers={
|
headers={
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'Authorization': 'Basic {}'.format(self.api_key)
|
'Authorization': 'Basic {}'.format(self.api_key)
|
||||||
}
|
},
|
||||||
|
timeout=60
|
||||||
)
|
)
|
||||||
|
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
@@ -117,6 +118,9 @@ class MMGClient(SmsClient):
|
|||||||
except RequestException as e:
|
except RequestException as e:
|
||||||
self.record_outcome(False, e.response)
|
self.record_outcome(False, e.response)
|
||||||
raise MMGClientResponseException(response=e.response, exception=e)
|
raise MMGClientResponseException(response=e.response, exception=e)
|
||||||
|
except HTTPError as e:
|
||||||
|
self.record_outcome(False, e.response)
|
||||||
|
raise MMGClientResponseException(response=e.response, exception=e)
|
||||||
finally:
|
finally:
|
||||||
elapsed_time = monotonic() - start_time
|
elapsed_time = monotonic() - start_time
|
||||||
self.statsd_client.timing("clients.mmg.request-time", elapsed_time)
|
self.statsd_client.timing("clients.mmg.request-time", elapsed_time)
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ register_errors(sms_callback_blueprint)
|
|||||||
|
|
||||||
@sms_callback_blueprint.route('/mmg', methods=['POST'])
|
@sms_callback_blueprint.route('/mmg', methods=['POST'])
|
||||||
def process_mmg_response():
|
def process_mmg_response():
|
||||||
|
from time import sleep
|
||||||
|
sleep(20)
|
||||||
client_name = 'MMG'
|
client_name = 'MMG'
|
||||||
data = json.loads(request.data)
|
data = json.loads(request.data)
|
||||||
errors = validate_callback_data(data=data,
|
errors = validate_callback_data(data=data,
|
||||||
|
|||||||
Reference in New Issue
Block a user