push notifs: Add logging on creating device tokens.

We'd been getting errors from APNs that appeared to say that the
device tokens we were trying to send to were invalid.  It turned out
that the device tokens didn't match the "topic" (i.e. app ID) we were
sending, which was because the topic was wrong, which was because we
were using the wrong SSL cert.  But for a while we thought it might be
that we were somehow messing up the device tokens we put into the
database.  This logging helped us work out that wasn't the issue, and
would have helped our debugging sooner.
This commit is contained in:
Greg Price
2017-08-17 22:02:50 -07:00
committed by Tim Abbott
parent f0c4f4d4bc
commit 3bceeec89f

View File

@@ -411,6 +411,9 @@ def send_notifications_to_bouncer(user_profile_id, apns_payload, gcm_payload):
def add_push_device_token(user_profile, token_str, kind, ios_app_id=None): def add_push_device_token(user_profile, token_str, kind, ios_app_id=None):
# type: (UserProfile, bytes, int, Optional[str]) -> None # type: (UserProfile, bytes, int, Optional[str]) -> None
logging.info("New push device: %d %r %d %r",
user_profile.id, token_str, kind, ios_app_id)
# If we're sending things to the push notification bouncer # If we're sending things to the push notification bouncer
# register this user with them here # register this user with them here
if uses_notification_bouncer(): if uses_notification_bouncer():
@@ -424,6 +427,7 @@ def add_push_device_token(user_profile, token_str, kind, ios_app_id=None):
if kind == PushDeviceToken.APNS: if kind == PushDeviceToken.APNS:
post_data['ios_app_id'] = ios_app_id post_data['ios_app_id'] = ios_app_id
logging.info("Sending new push device to bouncer: %r", post_data)
send_to_push_bouncer('POST', 'register', post_data) send_to_push_bouncer('POST', 'register', post_data)
return return
@@ -438,8 +442,11 @@ def add_push_device_token(user_profile, token_str, kind, ios_app_id=None):
kind=kind, kind=kind,
ios_app_id=ios_app_id)) ios_app_id=ios_app_id))
if not created: if not created:
logging.info("Existing push device updated.")
token.last_updated = timezone_now() token.last_updated = timezone_now()
token.save(update_fields=['last_updated']) token.save(update_fields=['last_updated'])
else:
logging.info("New push device created.")
def remove_push_device_token(user_profile, token_str, kind): def remove_push_device_token(user_profile, token_str, kind):
# type: (UserProfile, bytes, int) -> None # type: (UserProfile, bytes, int) -> None