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

feat: make gcm calls use async callbacks #1296

Merged
merged 1 commit into from
Oct 8, 2018
Merged

feat: make gcm calls use async callbacks #1296

merged 1 commit into from
Oct 8, 2018

Conversation

jrconlin
Copy link
Member

@jrconlin jrconlin commented Oct 1, 2018

Closes #1291

@jrconlin jrconlin requested review from pjenvey and bbangert and removed request for pjenvey October 1, 2018 19:41
@codecov-io
Copy link

codecov-io commented Oct 1, 2018

Codecov Report

Merging #1296 into master will increase coverage by 0.02%.
The diff coverage is 99.56%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1296      +/-   ##
==========================================
+ Coverage   99.76%   99.78%   +0.02%     
==========================================
  Files          61       61              
  Lines        9897     9983      +86     
==========================================
+ Hits         9874     9962      +88     
+ Misses         23       21       -2
Impacted Files Coverage Δ
autopush/tests/test_router.py 100% <100%> (ø) ⬆️
autopush/tests/test_gcmclient.py 100% <100%> (ø) ⬆️
autopush/router/gcm.py 100% <100%> (+2.83%) ⬆️
autopush/tests/test_integration.py 100% <100%> (ø) ⬆️
autopush/router/gcmclient.py 100% <100%> (ø) ⬆️
autopush/web/webpush.py 99.61% <66.66%> (-0.39%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bf51b37...d67dcb4. Read the comment docs.

Copy link
Member

@bbangert bbangert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels like using inlineCallbacks would've made the GCM client implementation drastically simpler. Otherwise just some minor confusion about what 'gcm' means.

result = gcm.send(payload)
except RouterException:
raise # pragma nocover
d = gcm.send(payload)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does gcm actually refer to here? We pull a gcm off a gcm?


def _error(self, err, status, **kwargs):
"""Error handler that raises the RouterException"""
self.log.debug(err, **kwargs)
return RouterException(err, status_code=status, response_body=err,
**kwargs)

def _process_reply(self, reply, uaid_data, ttl, notification):
def _process_reply(self, gcm, uaid_data, ttl, notification):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This gcm is actually whatever the return value is, but above are two more uses of a 'gcm' that mean two other different things, and this gcm is neither of those gcm's. Are these all the same thing? Different things?

@jrconlin
Copy link
Member Author

jrconlin commented Oct 2, 2018

inlineCallbacks, or at least a better implementation may improve things, however when I first tried them the threads were returning too soon, where stacking the deferreds were not. I fully expect that months from now, when I understand this better, I'll swear about how horrible it all is and rewrite it.

For now, it should be good enough to validate if deferred processing will reduce CPU lock, and I can implement a better version for the pending FCM changeover.

self._options = options
self._sender = requests.post
self._sender = treq.request
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: there is a treq.post

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heh, I wanted to be explicit rather than rely on a wrapper. Not worth fighting over.


def _parse_response(self, message, content):
def parse_response(self, content, code, message):
if code in (400, 401, 404):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the 401 case should be removed from here just to help clarify as it would have already been handled in process()


def _error(self, err, status, **kwargs):
"""Error handler that raises the RouterException"""
self.log.debug(err, **kwargs)
return RouterException(err, status_code=status, response_body=err,
**kwargs)

def _process_reply(self, reply, uaid_data, ttl, notification):
def _process_reply(self, client, uaid_data, ttl, notification):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we get back a client now? (looks like all we need is its response, didn't see it utilized in tests but maybe I missed it)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're correct, we only really need client.response. It just felt odd to me that we were making a request of GCM and returning something else. Not a big deal, reverting.

@@ -527,6 +527,9 @@ def _router_completed(self, response, uaid_data, warning="",
router_type=None, vapid=None):
"""Called after router has completed successfully"""
# Log the time taken for routing
print("router_complete response: ", response)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good except is this leftover debugging?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

d'oh.

@@ -527,6 +527,8 @@ def _router_completed(self, response, uaid_data, warning="",
router_type=None, vapid=None):
"""Called after router has completed successfully"""
# Log the time taken for routing
if response is None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this needed as well? I figured it was also stray debugging, seems like route_notification still always returns something

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had originally included it because the router is technically a module that may fail. I might revisit this in the future, since you're right that we should still capture metric info off of it, but for now, it's unused code.

@bbangert bbangert merged commit fbc4ab8 into master Oct 8, 2018
@bbangert bbangert deleted the feat/1291a branch October 8, 2018 16:39
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants