Skip to content

Instantly share code, notes, and snippets.

@ChengLong
Last active August 29, 2015 14:00
Show Gist options
  • Save ChengLong/11216098 to your computer and use it in GitHub Desktop.
Save ChengLong/11216098 to your computer and use it in GitHub Desktop.
Fixing Bad Token Issue when using Grocer

Fixing grocer

If you use grocer for sending push, you may have notificed that one bad token can cause connection to drop and all subsequent tokens are not sent. And it fails silently... More on this here.

One workaround is to use this pull request (it's not merged in yet). After each push, you call

reply = pusher.read_reply

, which will try to get feedback from Apple. And if the connection is already dropped, it will reconnect. This is exactly what we want. e.g.

notifications.each do |n|
  pusher.push n
  reply = pusher.read_reply
  handle_reply if reply
end

Hope this will be merged into master soon.

Using houston

When using grocer, I found it's not fast to send push, expecially when there are invalid tokens.

tl;dr use houston. It's faster and more robust.

houston takes care of the following by default:

  1. maintains connection even if there are invalid tokens or other errors
  2. skips notifications with invalid tokens and keeps sending the rest
  3. you can know which are the notifications that are not sent successfully

I benchmarked these two library by sending notifications using this token array

tokens = [my_token, 'bad token', my_token] * 10

It took grocer with this fix around 38 seconds. While it took houston around 18 seconds.

Conclusion: use houston

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment