Skip to content

Commit

Permalink
Added support for timeouts in messaging module
Browse files Browse the repository at this point in the history
  • Loading branch information
carsongee committed Mar 8, 2018
1 parent bf783c3 commit 861b9ca
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions firebase_admin/messaging.py
Expand Up @@ -748,6 +748,7 @@ def __init__(self, app):
'GCLOUD_PROJECT environment variable.')
self._fcm_url = _MessagingService.FCM_URL.format(project_id)
self._client = _http_client.JsonHttpClient(credential=app.credential.get_credential())
self._timeout = app.options.get('httpTimeout')

@classmethod
def encode_message(cls, message):
Expand All @@ -757,10 +758,11 @@ def encode_message(cls, message):

def send(self, message, dry_run=False):
data = {'message': _MessagingService.encode_message(message)}
import ipdb; ipdb.set_trace()
if dry_run:
data['validate_only'] = True
try:
resp = self._client.body('post', url=self._fcm_url, json=data)
resp = self._client.body('post', url=self._fcm_url, json=data, timeout=self._timeout)
except requests.exceptions.RequestException as error:
if error.response is not None:
self._handle_fcm_error(error)
Expand Down Expand Up @@ -791,7 +793,12 @@ def make_topic_management_request(self, tokens, topic, operation):
url = '{0}/{1}'.format(_MessagingService.IID_URL, operation)
try:
resp = self._client.body(
'post', url=url, json=data, headers=_MessagingService.IID_HEADERS)
'post',
url=url,
json=data,
headers=_MessagingService.IID_HEADERS,
timeout=self._timeout
)
except requests.exceptions.RequestException as error:
if error.response is not None:
self._handle_iid_error(error)
Expand Down

0 comments on commit 861b9ca

Please sign in to comment.