Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Commit

Permalink
Merge pull request #829 from mozilla-services/bug/828
Browse files Browse the repository at this point in the history
bug: Do not attempt to register failed GCM registrations
  • Loading branch information
bbangert authored Feb 23, 2017
2 parents c94c7dd + 39bae0b commit f57286e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
13 changes: 2 additions & 11 deletions autopush/router/gcm.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

from autopush.exceptions import RouterException
from autopush.router.interface import RouterResponse
from autopush.utils import ms_time


class GCMRouter(object):
Expand Down Expand Up @@ -173,25 +172,17 @@ def _process_reply(self, reply, uaid_data, ttl, notification):
self._base_tags)
self.log.info("GCM failures: {failed()}",
failed=lambda: repr(reply.failed.items()))
self.router_table.register_user(
{"uaid": uaid_data.get('uaid'),
"router_type": uaid_data.get("router_type", "gcm"),
"connected_at": ms_time(),
"critical_failure": "Client is unreachable due to a "
"configuration error. Unable to "
"send message.",
})
raise RouterException("GCM unable to deliver", status_code=410,
response_body="GCM recipient not available.",
log_exception=False,
)

# retries:
if reply.needs_retry():
self.log.warn("GCM retry requested: {failed()}",
failed=lambda: repr(reply.failed.items()))
self.metrics.increment("updates.client.bridge.gcm.failed.retry",
self._base_tags)
self.log.warn("GCM retry requested: {failed()}",
failed=lambda: repr(reply.failed.items()))
raise RouterException("GCM failure to deliver, retry",
status_code=503,
response_body="Please try request later.",
Expand Down
10 changes: 10 additions & 0 deletions autopush/tests/test_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,19 +532,29 @@ def check_results(result):
def test_router_notification_gcm_failed_items(self):
self.mock_result.failed = dict(connect_data=True)
self.router.gcm['test123'] = self.gcm
self.router.metrics = Mock()
d = self.router.route_notification(self.notif, self.router_data)

def check_results(fail):
ok_(self.router.metrics.increment.called)
eq_(self.router.metrics.increment.call_args[0][0],
'updates.client.bridge.gcm.failed.failure')
eq_(fail.value.message, 'GCM unable to deliver')
self._check_error_call(fail.value, 410)
d.addBoth(check_results)
return d

def test_router_notification_gcm_needs_retry(self):
self.mock_result.needs_retry.return_value = True
self.router.gcm['test123'] = self.gcm
self.router.metrics = Mock()
d = self.router.route_notification(self.notif, self.router_data)

def check_results(fail):
ok_(self.router.metrics.increment.called)
eq_(self.router.metrics.increment.call_args[0][0],
'updates.client.bridge.gcm.failed.retry')
eq_(fail.value.message, 'GCM failure to deliver, retry')
self._check_error_call(fail.value, 503)
d.addBoth(check_results)
return d
Expand Down

0 comments on commit f57286e

Please sign in to comment.