Giter VIP home page Giter VIP logo

rpush's Introduction

Gem Version RPush Test Test Coverage Code Climate Join the chat at https://gitter.im/rpush/rpush

Rpush. The push notification service for Ruby.

Rpush aims to be the de facto gem for sending push notifications in Ruby. Its core goals are ease of use, reliability and a rich feature set. Rpush provides numerous advanced features not found in others gems, giving you greater control & insight as your project grows. These are a few of the reasons why companies worldwide rely on Rpush to deliver their notifications.

Supported Services

Feature Highlights

Getting Started

Add it to your Gemfile:

gem 'rpush'

Initialize Rpush into your project. Rails will be detected automatically.

$ cd /path/to/project
$ bundle
$ bundle exec rpush init

Create an App & Notification

Apple Push Notification Service

There is a choice of two modes (and one legacy mode) using certificates or using tokens:

If this is your first time using the APNs, you will need to generate either SSL certificates (for Apns2 or Apns) or an Encryption Key (p8) and an Encryption Key ID (for Apnsp8). See Generating Certificates for instructions.

Apnsp8

To use the p8 APNs Api:

app = Rpush::Apnsp8::App.new
app.name = "ios_app"
app.apn_key = File.read("/path/to/sandbox.p8")
app.environment = "development" # APNs environment.
app.apn_key_id = "APN KEY ID" # This is the Encryption Key ID provided by apple
app.team_id = "TEAM ID" # the team id - e.g. ABCDE12345
app.bundle_id = "BUNDLE ID" # the unique bundle id of the app, like com.example.appname
app.connections = 1
app.save!
n = Rpush::Apnsp8::Notification.new
n.app = Rpush::Apnsp8::App.find_by_name("ios_app")
n.device_token = "..." # hex string
n.alert = "hi mom!"
n.data = { foo: :bar }
n.save!
Apns2

(NB this uses the same protocol as Apnsp8, but authenticates with a certificate rather than tokens)

app = Rpush::Apns2::App.new
app.name = "ios_app"
app.certificate = File.read("/path/to/sandbox.pem")
app.environment = "development"
app.password = "certificate password"
app.bundle_id = "BUNDLE ID" # the unique bundle id of the app, like com.example.appname
app.connections = 1
app.save!
n = Rpush::Apns2::Notification.new
n.app = Rpush::Apns2::App.find_by_name("ios_app")
n.device_token = "..." # hex string
n.alert = "hi mom!"
n.data = {
  headers: { 'apns-topic': "BUNDLE ID" }, # the bundle id of the app, like com.example.appname. Not necessary if set on the app (see above)
  foo: :bar
}
n.save!

You should also implement the ssl_certificate_will_expire reflection to monitor when your certificate is due to expire.

Apns (legacy protocol)
app = Rpush::Apns::App.new
app.name = "ios_app"
app.certificate = File.read("/path/to/sandbox.pem")
app.environment = "development" # APNs environment.
app.password = "certificate password"
app.connections = 1
app.save!
n = Rpush::Apns::Notification.new
n.app = Rpush::Apns::App.find_by_name("ios_app")
n.device_token = "..." # hex string
n.alert = "hi mom!"
n.data = { foo: :bar }
n.save!
Safari Push Notifications

Using one of the notifications methods above, the url_args attribute is available for Safari Push Notifications.

Environment

The app environment for any Apns* option is "development" for XCode installs, and "production" for app store and TestFlight. Note that for Apns2 you can now use one (production + sandbox) certificate (you don't need a separate "sandbox" or development certificate), but if you do generate a development/sandbox certificate it can only be used for "development". With Apnsp8 tokens, you can target either "development" or "production" environments.

Firebase Cloud Messaging

FCM and GCM are – as of writing – compatible with each other. See also this comment for further references.

Please refer to the Firebase Console on where to find your auth_key (probably called Server Key there). To verify you have the right key, use tools like Postman, HTTPie, curl or similar before reporting a new issue. See also this comment.

app = Rpush::Gcm::App.new
app.name = "android_app"
app.auth_key = "..."
app.connections = 1
app.save!
n = Rpush::Gcm::Notification.new
n.app = Rpush::Gcm::App.find_by_name("android_app")
n.registration_ids = ["..."]
n.data = { message: "hi mom!" }
n.priority = 'high'        # Optional, can be either 'normal' or 'high'
n.content_available = true # Optional
# Optional notification payload. See the reference below for more keys you can use!
n.notification = { body: 'great match!',
                   title: 'Portugal vs. Denmark',
                   icon: 'myicon'
                 }
n.save!

FCM also requires you to respond to Canonical IDs.

Check the FCM reference for what keys you can use and are available to you. Note: Not all are yet implemented in Rpush.

Amazon Device Messaging

app = Rpush::Adm::App.new
app.name = "kindle_app"
app.client_id = "..."
app.client_secret = "..."
app.connections = 1
app.save!
n = Rpush::Adm::Notification.new
n.app = Rpush::Adm::App.find_by_name("kindle_app")
n.registration_ids = ["..."]
n.data = { message: "hi mom!"}
n.collapse_key = "Optional consolidationKey"
n.save!

For more documentation on ADM.

Windows Phone Notification Service (Windows Phone 8.0 and 7.x)

Uses the older Windows Phone 8 Toast template

app = Rpush::Wpns::App.new
app.name = "windows_phone_app"
app.client_id = # Get this from your apps dashboard https://dev.windows.com
app.client_secret = # Get this from your apps dashboard https://dev.windows.com
app.connections = 1
app.save!
n = Rpush::Wpns::Notification.new
n.app = Rpush::Wpns::App.find_by_name("windows_phone_app")
n.uri = "http://..."
n.data = {title:"MyApp", body:"Hello world", param:"user_param1"}
n.save!

Windows Notification Service (Windows 8.1, 10 Apps & Phone > 8.0)

Uses the more recent Toast template

The client_id here is the SID URL as seen here. Do not confuse it with the client_id on dashboard.

You can (optionally) include a launch argument by adding a launch key to the notification data.

You can (optionally) include an audio element by setting the sound on the notification.

app = Rpush::Wns::App.new
app.name = "windows_phone_app"
app.client_id = YOUR_SID_URL
app.client_secret = YOUR_CLIENT_SECRET
app.connections = 1
app.save!
n = Rpush::Wns::Notification.new
n.app = Rpush::Wns::App.find_by_name("windows_phone_app")
n.uri = "http://..."
n.data = {title:"MyApp", body:"Hello world", launch:"launch-argument"}
n.sound = "ms-appx:///mynotificationsound.wav"
n.save!

Windows Raw Push Notifications

Note: The data is passed as .to_json so only this format is supported, although raw notifications are meant to support any kind of data. Current data structure enforces hashes and .to_json representation is natural presentation of it.

n = Rpush::Wns::RawNotification.new
n.app = Rpush::Wns::App.find_by_name("windows_phone_app")
n.uri = 'http://...'
n.data = { foo: 'foo', bar: 'bar' }
n.save!

Windows Badge Push Notifications

Uses the badge template and the type wns/badge.

n = Rpush::Wns::BadgeNotification.new
n.app = Rpush::Wns::App.find_by_name("windows_phone_app")
n.uri = 'http://...'
n.badge = 4
n.save!

Pushy

Pushy is a highly-reliable push notification gateway, based on MQTT protocol for cross platform push notification delivery that includes web, Android, and iOS. One of its advantages is it allows for reliable notification delivery to Android devices in China where Google Cloud Messaging and Firebase Cloud Messaging are blocked and to custom hardware devices that use Android OS but are not using Google Play Services.

Note: current implementation of Pushy only supports Android devices and does not include subscriptions.

app = Rpush::Pushy::App.new
app.name = "android_app"
app.api_key = YOUR_API_KEY
app.connections = 1
app.save!
n = Rpush::Pushy::Notification.new
n.app = Rpush::Pushy::App.find_by_name("android_app")
n.registration_ids = ["..."]
n.data = { message: "hi mom!"}
n.time_to_live = 60 # seconds
n.save!

For more documentation on Pushy.

Webpush

Webpush is a protocol for delivering push messages to desktop browsers. It's supported by all major browsers (except Safari, you have to use one of the Apns transports for that).

Using VAPID, there is no need for the sender of push notifications to register upfront with push services (as was the case with the now legacy Mozilla or Google desktop push providers).

Instead, you generate a pair of keys and use the public key when subscribing users in your web app. The keys are stored along with an email address (which, according to the spec, can be used by push service providers to contact you in case of problems) in the certificates field of the Rpush Application record:

vapid_keypair = Webpush.generate_key.to_hash
app = Rpush::Webpush::App.new
app.name = 'webpush'
app.certificate = vapid_keypair.merge(subject: '[email protected]').to_json
app.connections = 1
app.save!

The subscription object you obtain from a subscribed browser holds an endpoint URL and cryptographic keys. When sending a notification, simply pass the whole subscription as sole member of the registration_ids collection:

n = Rpush::Webpush::Notification.new
n.app = Rpush::App.find_by_name("webpush")
n.registration_ids = [subscription]
n.data = { message: "hi mom!" }
n.save!

In order to send the same message to multiple devices, create one Notification per device, as passing multiple subscriptions at once as registration_ids is not supported.

Running Rpush

It is recommended to run Rpush as a separate process in most cases, though embedding and manual modes are provided for low-workload environments.

See rpush help for all available commands and options.

As a daemon

$ cd /path/to/project
$ rpush start

As a foreground process

$ cd /path/to/project
$ rpush start -f

On the command-line

$ rpush push

Rpush will deliver all pending notifications and then exit.

In a scheduled job

Rpush.push
Rpush.apns_feedback

See Push API for more details.

Embedded inside an existing process

if defined?(Rails)
  ActiveSupport.on_load(:after_initialize) do
    Rpush.embed
  end
else
  Rpush.embed
end

Call this during startup of your application, for example, by adding it to the end of config/rpush.rb. See Embedding API for more details.

Using mina

If you're using mina, there is a gem called mina-rpush which helps you control rpush.

Cleanup

Rpush leaves delivered notifications in the database. If you do not clear them out, they will take up more and more space. This isn't great for any database, but is especially problematic if using Redis as the Rpush store. Here is an example solution for cleaning up delivered notifications in Redis.

Configuration

See Configuration for a list of options.

Updating Rpush

You should run rpush init after upgrading Rpush to check for configuration and migration changes.

From The Wiki

General

Apple Push Notification Service

Firebase Cloud Messaging

Contributing

Running Tests

Rpush uses Appraisal to run tests against multiple versions of Ruby on Rails. This helps making sure that Rpush performs correctly with multiple Rails versions.

Rpush also uses RSpec for its tests.

Bootstrapping your test suite:

First, we need to setup a test database, rpush_test.

E.g. (postgres): psql -c 'create database rpush_test;' -U postgres >/dev/null

bundle install
bundle exec appraisal install

This will install all the required gems that requires to test against each version of Rails, which defined in gemfiles/*.gemfile.

To run a full test suite:
bundle exec appraisal rake

This will run RSpec against all versions of Rails.

To run a single test

You need to specify a BUNDLE_GEMFILE pointing to the gemfile before running the normal test command:

BUNDLE_GEMFILE=gemfiles/rails_5.2.gemfile rspec spec/unit/apns_feedback_spec.rb
Multiple database adapter support

When running specs, please note that the ActiveRecord adapter can be changed by setting the ADAPTER environment variable. For example: ADAPTER=postgresql rake.

Available adapters for testing are postgresql, jdbcpostgresql, mysql2, jdbcmysql, jdbch2, and sqlite3.

Note that the database username is changed at runtime to be the currently logged in user's name. So if you're testing with mysql and you're using a user named 'bob', you will need to grant a mysql user 'bob' access to the 'rpush_test' mysql database.

To switch between ActiveRecord and Redis, set the CLIENT environment variable to either active_record or redis.

rpush's People

Contributors

amaierhofer avatar andreaslillebo avatar aried3r avatar benlangfeld avatar biow0lf avatar blakewatters avatar darrylyip avatar dependabot[bot] avatar dianthudia avatar drn avatar dsantosmerino avatar gregblake avatar grosser avatar ileitch avatar jhottenstein avatar jkraemer avatar jsantos avatar krakatoa avatar latortuga avatar loadhigh avatar mariannegru avatar mattconnolly avatar maxsz avatar nattfodd avatar rofreg avatar skunkworker avatar tdtran avatar voidless avatar wilg avatar xenofex avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rpush's Issues

notification_failed not called on APNS error 8

If a set of notifications fails to be delivered due to a connection error (For instance, on APNS error code 8), the notification_delivered reflection will still be run for all the notifications and the notification_failed reflection will never be called.

Previous worker not sending notifications for new Apns Apps

Issue by saulm from Friday Jul 12, 2013 at 19:40 GMT
Originally opened as ileitch/rapns#141


Hi @ileitch, first of all thanks for the great work on the rapns gem,

I'm having a small issue and wanted to ask you about it:

When my rapns worker is running and I create a new Apns App, notifications are not send for this new app unless I restart the worker. Is it by design? have you run into this problem before? how have you addressed it?

I'm leaving you a small log sample from my app running on heroku. You can see there that I have to restart the worker so the notifications for the new app are sent.

Thanks in advance,

SM

2013-07-12T19:08:22.580927+00:00 app[rapns.1]: [2013-07-12 19:08:22] [51d7a9b24a85acb942000001_51d7a9c54a85ac1546000001] Connected to feedback.sandbox.push.apple.com:2196
2013-07-12T19:08:35.206160+00:00 app[rapns.1]: [2013-07-12 19:08:35] [51d20c2f92157af33d000001_51d20c4492157aad5c000001] Connected to feedback.sandbox.push.apple.com:2196
2013-07-12T19:08:40.995541+00:00 app[rapns.1]: [2013-07-12 19:08:40] [51c86bd9446ad7e40c000001_51df2a02b7606deb9e000003] Connected to feedback.sandbox.push.apple.com:2196
2013-07-12T19:09:22.911372+00:00 app[rapns.1]: [2013-07-12 19:09:22] [51d7a9b24a85acb942000001_51d7a9c54a85ac1546000001] Connected to feedback.sandbox.push.apple.com:2196
2013-07-12T19:09:32.415993+00:00 app[web.1]: Started PUT "/apns_app/51c86bd9446ad7e40c000001_51e0544ada3604a205000013.json" for 54.242.138.86 at 2013-07-12 19:09:32 +0000
2013-07-12T19:09:32.640924+00:00 heroku[router]: at=info method=PUT path=/apns_app/51c86bd9446ad7e40c000001_51e0544ada3604a205000013.json host=kumakore-pn-testing.herokuapp.com fwd="54.242.138.86" dyno=web.1 connect=1ms service=229ms status=404 bytes=4
2013-07-12T19:09:32.671748+00:00 app[web.1]: Started POST "/apns_app.json" for 54.242.138.86 at 2013-07-12 19:09:32 +0000
2013-07-12T19:09:32.893886+00:00 heroku[router]: at=info method=POST path=/apns_app.json host=kumakore-pn-testing.herokuapp.com fwd="54.242.138.86" dyno=web.1 connect=3ms service=233ms status=201 bytes=8979
2013-07-12T19:09:35.788412+00:00 app[rapns.1]: [2013-07-12 19:09:35] [51d20c2f92157af33d000001_51d20c4492157aad5c000001] Connected to feedback.sandbox.push.apple.com:2196
2013-07-12T19:09:41.444738+00:00 app[rapns.1]: [2013-07-12 19:09:41] [51c86bd9446ad7e40c000001_51df2a02b7606deb9e000003] Connected to feedback.sandbox.push.apple.com:2196
2013-07-12T19:10:23.125716+00:00 app[rapns.1]: [2013-07-12 19:10:23] [51d7a9b24a85acb942000001_51d7a9c54a85ac1546000001] Connected to feedback.sandbox.push.apple.com:2196
2013-07-12T19:10:36.255724+00:00 app[rapns.1]: [2013-07-12 19:10:36] [51d20c2f92157af33d000001_51d20c4492157aad5c000001] Connected to feedback.sandbox.push.apple.com:2196
2013-07-12T19:10:41.758498+00:00 app[rapns.1]: [2013-07-12 19:10:41] [51c86bd9446ad7e40c000001_51df2a02b7606deb9e000003] Connected to feedback.sandbox.push.apple.com:2196
2013-07-12T19:11:24.106996+00:00 app[rapns.1]: [2013-07-12 19:11:24] [51d7a9b24a85acb942000001_51d7a9c54a85ac1546000001] Connected to feedback.sandbox.push.apple.com:2196
2013-07-12T19:11:36.898421+00:00 app[rapns.1]: [2013-07-12 19:11:36] [51d20c2f92157af33d000001_51d20c4492157aad5c000001] Connected to feedback.sandbox.push.apple.com:2196
2013-07-12T19:11:41.989951+00:00 app[rapns.1]: [2013-07-12 19:11:41] [51c86bd9446ad7e40c000001_51df2a02b7606deb9e000003] Connected to feedback.sandbox.push.apple.com:2196
2013-07-12T19:12:24.488506+00:00 app[rapns.1]: [2013-07-12 19:12:24] [51d7a9b24a85acb942000001_51d7a9c54a85ac1546000001] Connected to feedback.sandbox.push.apple.com:2196
2013-07-12T19:12:37.756176+00:00 app[rapns.1]: [2013-07-12 19:12:37] [51d20c2f92157af33d000001_51d20c4492157aad5c000001] Connected to feedback.sandbox.push.apple.com:2196
2013-07-12T19:12:42.225265+00:00 app[rapns.1]: [2013-07-12 19:12:42] [51c86bd9446ad7e40c000001_51df2a02b7606deb9e000003] Connected to feedback.sandbox.push.apple.com:2196
2013-07-12T19:13:24.985560+00:00 app[rapns.1]: [2013-07-12 19:13:24] [51d7a9b24a85acb942000001_51d7a9c54a85ac1546000001] Connected to feedback.sandbox.push.apple.com:2196
2013-07-12T19:13:38.290682+00:00 app[rapns.1]: [2013-07-12 19:13:38] [51d20c2f92157af33d000001_51d20c4492157aad5c000001] Connected to feedback.sandbox.push.apple.com:2196
2013-07-12T19:13:42.562019+00:00 app[rapns.1]: [2013-07-12 19:13:42] [51c86bd9446ad7e40c000001_51df2a02b7606deb9e000003] Connected to feedback.sandbox.push.apple.com:2196
2013-07-12T19:14:25.327800+00:00 app[rapns.1]: [2013-07-12 19:14:25] [51d7a9b24a85acb942000001_51d7a9c54a85ac1546000001] Connected to feedback.sandbox.push.apple.com:2196
2013-07-12T19:14:38.752618+00:00 app[rapns.1]: [2013-07-12 19:14:38] [51d20c2f92157af33d000001_51d20c4492157aad5c000001] Connected to feedback.sandbox.push.apple.com:2196
2013-07-12T19:14:41.881781+00:00 app[web.1]: Started POST "/apns_notification.json" for 54.242.138.86 at 2013-07-12 19:14:41 +0000
2013-07-12T19:14:41.927946+00:00 heroku[router]: at=info method=POST path=/apns_notification.json host=kumakore-pn-testing.herokuapp.com fwd="54.242.138.86" dyno=web.1 connect=1ms service=50ms status=200 bytes=46
2013-07-12T19:14:43.237299+00:00 app[rapns.1]: [2013-07-12 19:14:43] [51c86bd9446ad7e40c000001_51df2a02b7606deb9e000003] Connected to feedback.sandbox.push.apple.com:2196
2013-07-12T19:15:25.613810+00:00 app[rapns.1]: [2013-07-12 19:15:25] [51d7a9b24a85acb942000001_51d7a9c54a85ac1546000001] Connected to feedback.sandbox.push.apple.com:2196
2013-07-12T19:15:39.036144+00:00 app[rapns.1]: [2013-07-12 19:15:39] [51d20c2f92157af33d000001_51d20c4492157aad5c000001] Connected to feedback.sandbox.push.apple.com:2196
2013-07-12T19:15:43.478576+00:00 app[rapns.1]: [2013-07-12 19:15:43] [51c86bd9446ad7e40c000001_51df2a02b7606deb9e000003] Connected to feedback.sandbox.push.apple.com:2196
2013-07-12T19:16:25.958095+00:00 app[rapns.1]: [2013-07-12 19:16:25] [51d7a9b24a85acb942000001_51d7a9c54a85ac1546000001] Connected to feedback.sandbox.push.apple.com:2196
2013-07-12T19:16:39.346176+00:00 app[rapns.1]: [2013-07-12 19:16:39] [51d20c2f92157af33d000001_51d20c4492157aad5c000001] Connected to feedback.sandbox.push.apple.com:2196
2013-07-12T19:16:44.364415+00:00 app[rapns.1]: [2013-07-12 19:16:44] [51c86bd9446ad7e40c000001_51df2a02b7606deb9e000003] Connected to feedback.sandbox.push.apple.com:2196
2013-07-12T19:16:54.204799+00:00 heroku[api]: Scale to rapns=0, web=1 by [email protected]
2013-07-12T19:16:54.404231+00:00 heroku[rapns.1]: State changed from up to down
2013-07-12T19:17:24.282347+00:00 heroku[api]: Scale to rapns=1, web=1 by [email protected]
2013-07-12T19:17:26.571824+00:00 app[rapns.1]: [2013-07-12 19:17:26] [51d7a9b24a85acb942000001_51d7a9c54a85ac1546000001] Connected to feedback.sandbox.push.apple.com:2196
2013-07-12T19:17:28.116026+00:00 heroku[rapns.1]: Starting process with command `bundle exec rapns testing`
2013-07-12T19:17:35.481290+00:00 app[rapns.1]: [2013-07-12 19:17:35] [519180ae1b883f8dce000003_51a806e5f3d4bbf25f000003] Started, 1 handler.
2013-07-12T19:17:35.481727+00:00 app[rapns.1]: [2013-07-12 19:17:35] [519806eb092df3d9f3000002_51a5b3e6995cfb7ba7000001] Started, 1 handler.
2013-07-12T19:17:35.481999+00:00 app[rapns.1]: [2013-07-12 19:17:35] [51ca7fcfdecea61e34000001_51cd2d4ac5ca585235000001] Started, 1 handler.
2013-07-12T19:17:35.482384+00:00 app[rapns.1]: [2013-07-12 19:17:35] [51d20c2f92157af33d000001_51d20c4492157aad5c000001] Started, 1 handler.
2013-07-12T19:17:35.514815+00:00 app[rapns.1]: [2013-07-12 19:17:35] [51d7a9b24a85acb942000001_51d7a9c54a85ac1546000001] Started, 1 handler.
2013-07-12T19:17:35.515314+00:00 app[rapns.1]: [2013-07-12 19:17:35] [51c86bd9446ad7e40c000001_51c936bf51d3fd637c000001] Started, 1 handler.
2013-07-12T19:17:35.515700+00:00 app[rapns.1]: [2013-07-12 19:17:35] [51c86bd9446ad7e40c000001_51df2a02b7606deb9e000003] Started, 1 handler.
2013-07-12T19:17:35.518169+00:00 app[rapns.1]: [2013-07-12 19:17:35] [51c86bd9446ad7e40c000001_51e0544ada3604a205000013] Started, 1 handler.
2013-07-12T19:17:35.756274+00:00 app[rapns.1]: [2013-07-12 19:17:35] [51c86bd9446ad7e40c000001_51e0544ada3604a205000013] Connected to feedback.sandbox.push.apple.com:2196
2013-07-12T19:17:35.768638+00:00 app[rapns.1]: [2013-07-12 19:17:35] [51c86bd9446ad7e40c000001_51df2a02b7606deb9e000003] Connected to feedback.sandbox.push.apple.com:2196
2013-07-12T19:17:35.774624+00:00 app[rapns.1]: [2013-07-12 19:17:35] [51d20c2f92157af33d000001_51d20c4492157aad5c000001] Connected to feedback.sandbox.push.apple.com:2196
2013-07-12T19:17:35.776117+00:00 app[rapns.1]: [2013-07-12 19:17:35] [51d7a9b24a85acb942000001_51d7a9c54a85ac1546000001] Connected to feedback.sandbox.push.apple.com:2196
2013-07-12T19:17:35.798481+00:00 app[rapns.1]: [2013-07-12 19:17:35] [51c86bd9446ad7e40c000001_51e0544ada3604a205000013] Connected to gateway.sandbox.push.apple.com:2195
2013-07-12T19:17:35.902123+00:00 heroku[router]: at=info method=GET path=/docs host=kumakore-pn-testing.herokuapp.com fwd="184.73.237.85" dyno=web.1 connect=2ms service=8ms status=200 bytes=1651
2013-07-12T19:17:36.095277+00:00 app[rapns.1]: [2013-07-12 19:17:36] [51c86bd9446ad7e40c000001_51e0544ada3604a205000013] 291 sent to 5ab99ddde083b12166b6563ef126f9e6ac731cf30f934a36184b4172481de23c
2013-07-12T19:17:41.056852+00:00 app[rapns.1]: [2013-07-12 19:17:41] [51d20c2f92157af33d000001_51d20c4492157aad5c000001] Connected to feedback.sandbox.push.apple.com:2196
2013-07-12T19:17:45.015249+00:00 app[rapns.1]: [2013-07-12 19:17:45] [51c86bd9446ad7e40c000001_51df2a02b7606deb9e000003] Connected to feedback.sandbox.push.apple.com:2196

Heroku - sslv3 alert certificate expired

 [ERROR] OpenSSL::SSL::SSLError, SSL_connect returned=1 errno=0 state=SSLv3 read finished A: sslv3 alert certificate expired

Anyone experienced this on Heroku?

Killing pending notifications

A lot of notifications were created in my database, while the rpush process was stopped.
Now I want to kill those notifications before I restart the rpush process.
I don't want the rpush to send the previous notifications now.

Is there an easy way to do this?
How does Rpush picks up non delivered notification?

Btw thank you for the wonderful gem. :)

Infinite re-sends on Connection Timeout to Database

When rpush loads a notification for sending but fails to save its delivered state due to a connection timeout, it re-sends the same notification until it can reconnect. This results in the user being spammed with the same notification until the timeout situation is resolved.

[2014-07-24 17:12:41] [iOS SDK18] 366 sent to a6f61a1c67a7d87d99ce009dc6faad457ad18264f38cebcc350ebb9b901f0f93
[2014-07-24 17:12:41] [iOS SDK18] 367 sent to a6f61a1c67a7d87d99ce009dc6faad457ad18264f38cebcc350ebb9b901f0f93
[2014-07-24 17:12:46] [ERROR] ActiveRecord::ConnectionTimeoutError, could not obtain a database connection within 5.000 seconds (waited 5.000 seconds)
/var/www/lqd.io/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:190:in `block in wait_poll'
/var/www/lqd.io/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:181:in `loop'
/var/www/lqd.io/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:181:in `wait_poll'
/var/www/lqd.io/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:136:in `block in poll'
/usr/local/rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
/var/www/lqd.io/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:146:in `synchronize'
/var/www/lqd.io/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:134:in `poll'
/var/www/lqd.io/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:418:in `acquire_connection'
/var/www/lqd.io/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:351:in `block in checkout'
/usr/local/rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
/var/www/lqd.io/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:350:in `checkout'
/var/www/lqd.io/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:265:in `block in connection'
/usr/local/rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
/var/www/lqd.io/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:264:in `connection'
/var/www/lqd.io/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:294:in `with_connection'
/var/www/lqd.io/shared/bundle/ruby/2.1.0/gems/rpush-1.0.0/lib/rpush/daemon/store/active_record/reconnectable.rb:24:in `with_database_reconnect_and_retry'
/var/www/lqd.io/shared/bundle/ruby/2.1.0/gems/rpush-1.0.0/lib/rpush/daemon/store/active_record.rb:64:in `mark_batch_delivered'
/var/www/lqd.io/shared/bundle/ruby/2.1.0/gems/rpush-1.0.0/lib/rpush/daemon/batch.rb:87:in `complete_delivered'
/var/www/lqd.io/shared/bundle/ruby/2.1.0/gems/rpush-1.0.0/lib/rpush/daemon/batch.rb:75:in `block in complete'
/var/www/lqd.io/shared/bundle/ruby/2.1.0/gems/rpush-1.0.0/lib/rpush/daemon/batch.rb:73:in `each'
/var/www/lqd.io/shared/bundle/ruby/2.1.0/gems/rpush-1.0.0/lib/rpush/daemon/batch.rb:73:in `complete'
/var/www/lqd.io/shared/bundle/ruby/2.1.0/gems/rpush-1.0.0/lib/rpush/daemon/batch.rb:58:in `block in notification_dispatched'
/var/www/lqd.io/shared/bundle/ruby/2.1.0/gems/rpush-1.0.0/lib/rpush/daemon/batch.rb:56:in `synchronize'
/var/www/lqd.io/shared/bundle/ruby/2.1.0/gems/rpush-1.0.0/lib/rpush/daemon/batch.rb:56:in `notification_dispatched'
/var/www/lqd.io/shared/bundle/ruby/2.1.0/gems/rpush-1.0.0/lib/rpush/daemon/dispatcher_loop.rb:49:in `dispatch'
/var/www/lqd.io/shared/bundle/ruby/2.1.0/gems/rpush-1.0.0/lib/rpush/daemon/dispatcher_loop.rb:16:in `block (2 levels) in start'
/var/www/lqd.io/shared/bundle/ruby/2.1.0/gems/rpush-1.0.0/lib/rpush/daemon/dispatcher_loop.rb:15:in `loop'
/var/www/lqd.io/shared/bundle/ruby/2.1.0/gems/rpush-1.0.0/lib/rpush/daemon/dispatcher_loop.rb:15:in `block in start'
[2014-07-24 17:12:46] [ios android sdk6] Connected to feedback.sandbox.push.apple.com:2196
[2014-07-24 17:12:46] [iOS SDK18] Connected to feedback.sandbox.push.apple.com:2196
[2014-07-24 17:12:47] [iOS SDK18] 366 sent to a6f61a1c67a7d87d99ce009dc6faad457ad18264f38cebcc350ebb9b901f0f93
[2014-07-24 17:12:47] [iOS SDK18] 367 sent to a6f61a1c67a7d87d99ce009dc6faad457ad18264f38cebcc350ebb9b901f0f93

Multiple databases support

Issue by sonxurxo from Thursday Nov 28, 2013 at 17:37 GMT
Originally opened as ileitch/rapns#183


Hi,

It would be nice if you could set somewhere the database to use by rapns.

I'm working on some projects and all of them are going to use rapns on the same machine, and my problem comes with the "only 1 instance of rapns" restriction.

My solution: I have a "master" rails app which I only use to configure and start rapns (daemon mode, e.g. "$ rapns production"). This app connects to the "rapns" database.

My other apps have their own database, and also access the rapns one. When I have to send a notification, I'm having to specify the rapns database connection with something like:

Rapns::App.establish_connection "rapns_#{Rails.env}"
Rapns::Notification.establish_connection "rapns_#{Rails.env}"

before creating the notification, to let ActiveRecord to find rapns classes.

So it would be great if you could specify somewhere the database configuration where rapns model objects live, in the initializer, for instance.

ActiveRecord::ConnectionTimeoutError

Issue by j-mcnally from Thursday Jan 23, 2014 at 00:56 GMT
Originally opened as ileitch/rapns#196


[2014-01-23 00:43:04] [ERROR] ActiveRecord::ConnectionTimeoutError, could not obtain a database connection within 5.000 seconds (waited 5.000 seconds)
2014-01-23T00:43:04.558462+00:00 app[web.1]: /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:190:in `block in wait_poll'
2014-01-23T00:43:04.558462+00:00 app[web.1]: /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:181:in `loop'
2014-01-23T00:43:04.558462+00:00 app[web.1]: /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:181:in `wait_poll'
2014-01-23T00:43:04.558462+00:00 app[web.1]: /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:136:in `block in poll'
2014-01-23T00:43:04.558462+00:00 app[web.1]: /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
2014-01-23T00:43:04.558462+00:00 app[web.1]: /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:423:in `acquire_connection'
2014-01-23T00:43:04.558462+00:00 app[web.1]: /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:356:in `block in checkout'
2014-01-23T00:43:04.558841+00:00 app[web.1]: /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
2014-01-23T00:43:04.558841+00:00 app[web.1]: /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:355:in `checkout'
2014-01-23T00:43:04.558841+00:00 app[web.1]: /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:265:in `block in connection'
2014-01-23T00:43:04.558462+00:00 app[web.1]: /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:134:in `poll'
2014-01-23T00:43:04.558462+00:00 app[web.1]: /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:146:in `synchronize'
2014-01-23T00:43:04.558841+00:00 app[web.1]: /app/vendor/bundle/ruby/2.0.0/gems/rapns-3.4.1/lib/rapns/daemon/store/active_record/reconnectable.rb:17:in `with_database_reconnect_and_retry'
2014-01-23T00:43:04.558841+00:00 app[web.1]: /app/vendor/bundle/ruby/2.0.0/gems/rapns-3.4.1/lib/rapns/daemon/store/active_record.rb:12:in `deliverable_notifications'
2014-01-23T00:43:04.558841+00:00 app[web.1]: /app/vendor/bundle/ruby/2.0.0/gems/rapns-3.4.1/lib/rapns/daemon/feeder.rb:42:in `enqueue_notifications'
2014-01-23T00:43:04.559166+00:00 app[web.1]: /app/vendor/bundle/ruby/2.0.0/gems/rapns-3.4.1/lib/rapns/daemon/feeder.rb:27:in `loop'
2014-01-23T00:43:04.559166+00:00 app[web.1]: /app/vendor/bundle/ruby/2.0.0/gems/rapns-3.4.1/lib/rapns/daemon/feeder.rb:27:in `feed_forever'
2014-01-23T00:43:04.558841+00:00 app[web.1]: /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:294:in `with_connection'
2014-01-23T00:43:04.558841+00:00 app[web.1]: /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:264:in `connection'
2014-01-23T00:43:04.558841+00:00 app[web.1]: /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
2014-01-23T00:43:04.559166+00:00 app[web.1]: /app/vendor/bundle/ruby/2.0.0/gems/rapns-3.4.1/lib/rapns/daemon/feeder.rb:11:in `block in start'
2014-01-23T00:43:04.558841+00:00 app[web.1]: /app/vendor/bundle/ruby/2.0.0/gems/rapns-3.4.1/lib/rapns/daemon/feeder.rb:28:in `block in feed_forever'

I am running on heroku and have been getting quite a bit of these, i think its a heroku issue but wanted confirm i dont need to be catching and reconnecting anywhere?

help configure production

I finished configure rpush in my system and run good in development environment but in production doesn't work when I try to send notification

rpush stops working after several hours of activity

I have an rpush instance running on a server with several dozen Rpush::Apns (Sandbox & production) and Rpush::Gcm apps. It also polls the APNS feedback service every 180 seconds.

After around 24 hours, rpush appears to stop working and no longer writes anything to the log file. Restarting it resolves the problem, but of course this is not a good long term solution.

I attached GDB to the process and ran rb_backtrace. Here is the output:

from /var/www/APP/shared/bundle/ruby/2.1.0/bin/rpush:23:in `<main>'
from /var/www/APP/shared/bundle/ruby/2.1.0/bin/rpush:23:in `load'
from /var/www/APP/shared/bundle/ruby/2.1.0/bundler/gems/rpush-b6ea10de660e/bin/rpush:36:in `<top (required)>'
from /var/www/APP/shared/bundle/ruby/2.1.0/bundler/gems/rpush-b6ea10de660e/lib/rpush/daemon.rb:61:in `start'
from /var/www/APP/shared/bundle/ruby/2.1.0/bundler/gems/rpush-b6ea10de660e/lib/rpush/daemon/feeder.rb:14:in `start'
from /var/www/APP/shared/bundle/ruby/2.1.0/bundler/gems/rpush-b6ea10de660e/lib/rpush/daemon/feeder.rb:32:in `feed_forever'
from /var/www/APP/shared/bundle/ruby/2.1.0/bundler/gems/rpush-b6ea10de660e/lib/rpush/daemon/feeder.rb:32:in `loop'
from /var/www/APP/shared/bundle/ruby/2.1.0/bundler/gems/rpush-b6ea10de660e/lib/rpush/daemon/feeder.rb:34:in `block in feed_forever'
from /var/www/APP/shared/bundle/ruby/2.1.0/bundler/gems/rpush-b6ea10de660e/lib/rpush/daemon/interruptible_sleep.rb:26:in `sleep'
from /var/www/APP/shared/bundle/ruby/2.1.0/bundler/gems/rpush-b6ea10de660e/lib/rpush/daemon/interruptible_sleep.rb:26:in `select'

This seems to indicate that it's stuck in this code, on line "rs, = IO.select(read_ports, nil, nil, timeout) rescue nil"

def sleep(timeout)
    read_ports = [@sleep_reader]
    read_ports << @udp_wakeup if @udp_wakeup
    rs, = IO.select(read_ports, nil, nil, timeout) rescue nil

    # consume all data on the readable io's so that our next call will wait for more data
    perform_io(rs, @sleep_reader, :read_nonblock)
    perform_io(rs, @udp_wakeup, :recv_nonblock)

    !rs.nil? && rs.any?
  end

I also tried attaching to the process using your Hijack tool, but couldn't get it working.

Support for New APNS format

Looking at ./lib/rpush/client/active_model/apns/notification.rb , it looks like this gem is currently only supporting the LEGACY APNS "Enhanced Noticication Format"
where the notification packet starts with a "1"

see:
https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/LegacyFormat.html#//apple_ref/doc/uid/TP40008194-CH105-SW1

When are you planning on updating the code to support the newer APNS format starting
with a "2" ?

https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/CommunicatingWIthAPS.html

APNS Feedback App is a string?

What is the app attribute of the Rpush::Apns::Feedback supposed to contain? Is it the app's ID in string form, is it the name, is it just a to_s? Why is it a string anyway?

I'm using v1.0.0 which is the one installed through the gemfile, I'm assuming it's the latest stable release.

Uninitialized constant Rpush::Daemon

Hi :)

I'm currently configuring the rpush gem to be able to report some data to New Relic, and for that I would like to use this callback in the rpush.rb file:

  Rpush::Daemon::AppRunner.runners.each do |app_id, runner|
     runner.app
     runner.queue_size

     ::NewRelic::Agent.record_metric("Custom/Push/APNS/queue/#{runner.app.name}/queue", runner.queue_size)
  end

Unfortunately, it triggers this error when running:
rpush development -f

/Users/Jeremy/Documents/rails/MobilePushNotificationService/MobilePushNotificationService/config/initializers/rpush.rb:42:in `block in <top (required)>': uninitialized constant Rpush::Daemon (NameError)
    from /Users/Jeremy/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rpush-1.0.0/lib/rpush/reflection.rb:3:in `reflect'

Any idea how to fix it ?

Thank you in advance for your help!
Jeremy.

What's the performance benchmarks of rpush?

I was wondering if there are any performance benchmarks or any information that could give us a rough idea of how many notifications rpush can process per minute? I'm evaluating some APNs ruby libs and this is a promising one.

NameError, uninitialized constant Rapns::Daemon::Apn

Issue by masterkain from Tuesday Jan 28, 2014 at 14:45 GMT
Originally opened as ileitch/rapns#197


Hello,
I upgraded from 16e52d8 to 83088ba and I'm getting this exception at startup.

[2014-01-28 15:42:08] [ERROR] [MyApp] Exception raised during startup. Notifications will not be delivered for this app.
[2014-01-28 15:42:08] [ERROR] NameError, uninitialized constant Rapns::Daemon::Apn
[snip]/ruby-2.1.0/gems/activesupport-4.0.2/lib/active_support/inflector/methods.rb:228:in `const_get'
[snip]/ruby-2.1.0/gems/activesupport-4.0.2/lib/active_support/inflector/methods.rb:228:in `block in constantize'
[snip]/ruby-2.1.0/gems/activesupport-4.0.2/lib/active_support/inflector/methods.rb:224:in `each'
[snip]/ruby-2.1.0/gems/activesupport-4.0.2/lib/active_support/inflector/methods.rb:224:in `inject'
[snip]/ruby-2.1.0/gems/activesupport-4.0.2/lib/active_support/inflector/methods.rb:224:in `constantize'
[snip]/ruby-2.1.0/gems/activesupport-4.0.2/lib/active_support/core_ext/string/inflections.rb:66:in `constantize'
[snip]/ruby-2.1.0/bundler/gems/rapns-83088baf6600/lib/rapns/daemon/app_runner.rb:168:in `service_module'
[snip]/ruby-2.1.0/bundler/gems/rapns-83088baf6600/lib/rapns/daemon/app_runner.rb:160:in `new_dispatcher_loop'
[snip]/ruby-2.1.0/bundler/gems/rapns-83088baf6600/lib/rapns/daemon/app_runner.rb:73:in `block in start'
[snip]/ruby-2.1.0/bundler/gems/rapns-83088baf6600/lib/rapns/daemon/app_runner.rb:73:in `times'
[snip]/ruby-2.1.0/bundler/gems/rapns-83088baf6600/lib/rapns/daemon/app_runner.rb:73:in `start'
[snip]/ruby-2.1.0/bundler/gems/rapns-83088baf6600/lib/rapns/daemon/app_runner.rb:37:in `sync_app'
[snip]/ruby-2.1.0/bundler/gems/rapns-83088baf6600/lib/rapns/daemon/app_runner.rb:26:in `block in sync'
[snip]/ruby-2.1.0/gems/activerecord-4.0.2/lib/active_record/relation/delegation.rb:13:in `each'
[snip]/ruby-2.1.0/gems/activerecord-4.0.2/lib/active_record/relation/delegation.rb:13:in `each'
[snip]/ruby-2.1.0/bundler/gems/rapns-83088baf6600/lib/rapns/daemon/app_runner.rb:26:in `sync'
[snip]/ruby-2.1.0/bundler/gems/rapns-83088baf6600/lib/rapns/daemon.rb:60:in `start'
[snip]/ruby-2.1.0/bundler/gems/rapns-83088baf6600/bin/rapns:36:in `<top (required)>'
[snip]/ruby-2.1.0/bin/rapns:23:in `load'
[snip]/ruby-2.1.0/bin/rapns:23:in `<main>'
[snip]/ruby-2.1.0/bin/ruby_executable_hooks:15:in `eval'
[snip]/ruby-2.1.0/bin/ruby_executable_hooks:15:in `<main>'

Signal Handling is not working in ruby 2.1.1

Signals are trapped by the Signal Handler correctly but they're not being handled.

With the following monkey patches:

module Rpush
  module Daemon
    class SignalHandler
      def self.start
        return unless trap_signals?
        @shutting_down = false
        read_io, @write_io = IO.pipe
        start_handler(read_io)
        Rpush.logger.info "Trapping Signals"
        %w(INT TERM HUP USR2).each do |signal|
          Signal.trap(signal) {
            Thread.new { Rpush.logger.info "Before #{signal} Write" }
            @write_io.write("#{Signal.list[signal]}\n")
            Thread.new { Rpush.logger.info "After #{signal} Write" }
          }
        end
      end

      def self.start_handler(read_io)
        @thread = Thread.new do
          loop do
            Rpush.logger.info "Reading pipe..."
            case read_io.readline.strip.to_i
            when Signal.list['HUP']
              Rpush.logger.info "Signal HUP Caught."
              Synchronizer.sync
              Feeder.wakeup
            when Signal.list['USR2']
              Rpush.logger.info "Signal USR2 Caught."
              AppRunner.debug
            when Signal.list['INT'], Signal.list['TERM']
              Rpush.logger.info "Signal INT/TERM Caught."
              Thread.new { handle_shutdown_signal }
            else
              Rpush.logger.info "Unknown Signal Caught."
              break
            end
          end
        end
      end
    end
  end
end

And this input:

bundle exec rpush development
kill -s HUP "$(< tmp/pids/rpush.pid)"
kill -s USR2 "$(< tmp/pids/rpush.pid)"
kill -s INT "$(< tmp/pids/rpush.pid)"
kill -s TERM "$(< tmp/pids/rpush.pid)"

We get in the log output:

[2014-08-11 14:58:06] Reading pipe...
[2014-08-11 14:58:06] Trapping Signals
[2014-08-11 14:58:33] After HUP Write
[2014-08-11 14:58:33] Before HUP Write
[2014-08-11 14:58:43] Before USR2 Write
[2014-08-11 14:58:43] After USR2 Write
[2014-08-11 14:58:47] After INT Write
[2014-08-11 14:58:47] Before INT Write
[2014-08-11 14:58:52] Before TERM Write
[2014-08-11 14:58:52] After TERM Write

And we can observe that the rpush process is still up:

ps aux | grep rpush
93784   0.0  0.0  2432772    148 s005  S+   Fri06PM   0:00.01 tail -f log/rpush.log
96385   0.0  0.0  2432784    600 s003  S+    2:50PM   0:00.00 grep rpush
96361   0.0  0.8  2627160  64232   ??  S     2:49PM   0:00.14 rpush | development | 0 queued | 2 dispatchers   

So the loop never loops; the handler thread is stuck reading from IO. This is probably due to the new restrictions in signal handling code of Ruby 2.1. Writing to a pipe probably uses a Mutex which is not allowed because it can block.

"ArgumentError, invalid slice size" when only one notification is being sent

I am running rpush on heroku with stock configurations. When I try to queue a single test notification I get this error. When I send multiples it seems to be fine.

Any thoughts on if this is an issue on my side or an error in the enqueue method on the app_runner?

2014-07-30T22:22:23.222745+00:00 app[rpush.1]: [2014-07-30 22:22:23] [ERROR] ArgumentError, invalid slice size
2014-07-30T22:22:23.222751+00:00 app[rpush.1]: /app/vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.2/lib/active_support/core_ext/array/grouping.rb:34:in `each_slice'
2014-07-30T22:22:23.222753+00:00 app[rpush.1]: /app/vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.2/lib/active_support/core_ext/array/grouping.rb:34:in `in_groups_of'
2014-07-30T22:22:23.222755+00:00 app[rpush.1]: /app/vendor/bundle/ruby/2.1.0/bundler/gems/rpush-5653cabd82f5/lib/rpush/daemon/app_runner.rb:95:in `enqueue'
2014-07-30T22:22:23.222756+00:00 app[rpush.1]: /app/vendor/bundle/ruby/2.1.0/bundler/gems/rpush-5653cabd82f5/lib/rpush/daemon/app_runner.rb:17:in `block in enqueue'
2014-07-30T22:22:23.222758+00:00 app[rpush.1]: /app/vendor/bundle/ruby/2.1.0/bundler/gems/rpush-5653cabd82f5/lib/rpush/daemon/app_runner.rb:15:in `each'
2014-07-30T22:22:23.222760+00:00 app[rpush.1]: /app/vendor/bundle/ruby/2.1.0/bundler/gems/rpush-5653cabd82f5/lib/rpush/daemon/app_runner.rb:15:in `enqueue'
2014-07-30T22:22:23.222777+00:00 app[rpush.1]: /app/vendor/bundle/ruby/2.1.0/bundler/gems/rpush-5653cabd82f5/lib/rpush/daemon/feeder.rb:43:in `enqueue_notifications'
2014-07-30T22:22:23.222779+00:00 app[rpush.1]: /app/vendor/bundle/ruby/2.1.0/bundler/gems/rpush-5653cabd82f5/lib/rpush/daemon/feeder.rb:28:in `block (2 levels) in feed_forever'
2014-07-30T22:22:23.222780+00:00 app[rpush.1]: /app/vendor/bundle/ruby/2.1.0/bundler/gems/rpush-5653cabd82f5/lib/rpush/daemon/feeder.rb:27:in `loop'
2014-07-30T22:22:23.222782+00:00 app[rpush.1]: /app/vendor/bundle/ruby/2.1.0/bundler/gems/rpush-5653cabd82f5/lib/rpush/daemon/feeder.rb:27:in `block in feed_forever'

Start rpsuh on reboot

Hi guys,

A little sysadmin advice please.

Currently, after a reboot I have to remember to login and use the following command:
bundle exec rush production

Is there any way I can have rpush startup on reboot without having to launch it manually?

Thanks in advance.

rpush daemon doesn't check apns notification for new apps

It seems that rpush just check notifications for apps that already exist when launching the daemon.
I created a new notification for a new app and it wasn't delivered, I see in the console that the rpush query is allways the same:

 SELECT `rpush_notifications`.* FROM `rpush_notifications` WHERE (delivered = 0 AND failed = 0 AND (deliver_after IS NULL OR deliver_after < '2014-04-23 16:07:28')) AND (app_id IN (1,3)) LIMIT 100

It is always looking for new notifications for the app 1 and 3 only, no matter if I created a new notification for a new app (number 4 for instance)?

What can I do for DB Schema Awareness?

Hi,
I have a postgres database with a multi tenant architecture. Each client gets their own set of tables inside their own schema. rpush is able to find the notifications because the ActiveRecord::Base.connection.schema_search_path is set properly but it can't seem to mark the records as delivered (it looks in the public schema by default and the table isn't there).
ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: relation "rapns_notifications" does not exist LINE 5: ...id = '"rapns_notifications"'::regclass AND a.attnum > 0 AND NOT a.attisdropped ORDER BY a.attnum

/vendor/bundle/ruby/1.9.1/gems/rapns-3.4.1/lib/rapns/daemon/store/active_record.rb:45 in "mark_batch_delivered"
/vendor/bundle/ruby/1.9.1/gems/rapns-3.4.1/lib/rapns/daemon/batch.rb:81 in "complete_delivered"
/vendor/bundle/ruby/1.9.1/gems/rapns-3.4.1/lib/rapns/daemon/batch.rb:69 in "block in complete"
/vendor/bundle/ruby/1.9.1/gems/rapns-3.4.1/lib/rapns/daemon/batch.rb:67 in "each"
/vendor/bundle/ruby/1.9.1/gems/rapns-3.4.1/lib/rapns/daemon/batch.rb:67 in "complete"
/vendor/bundle/ruby/1.9.1/gems/rapns-3.4.1/lib/rapns/daemon/batch.rb:52 in "block in notification_processed"

I'm willing to patch but could you help point me in the right direction? I'm having trouble wrapping my little mind around the multi-threaded code here. Is there somewhere I can set an option or store a variable that will be accessible to all the threads?

Thanks in advance and thanks for this excellent ruby gem!

Hot updates signal doesn't work in Ruby 2.1.2

Hot updates signal doesn't work in Ruby 2.1.2.
After receiving HUP signal I can see only that Rpush check new notifications

SELECT `rpush_notifications`.* FROM `rpush_notifications` WHERE (delivered = 0 AND failed = 0 AND (deliver_after IS NULL OR deliver_after < '2014-05-23 14:38:44')) AND (app_id IN (4,5,14,16)) LIMIT 1024

So, old runners don't die and new runners don't start.

GCM returns an error for messages with Spanish characters

Issue by dmccarty from Wednesday Dec 18, 2013 at 12:43 GMT
Originally opened as ileitch/rapns#190


This may very well be user stupidity on my part but I am pushing a mix of Apns and GCM notifications containing the following message:

'Abra el App de El Rey y Clip para la oportunidad de ganar 4 boletos para ir a Zoo Lights en el Zoológico de Portland!

Apns works fine but GCM returns an error 400. When I change Zoológico to Zoologico it works. Is there some encoding I should be doing perhaps?

Feature Request: Read errors from APNS socket asynchronously

Issue by jefflopes from Monday Aug 12, 2013 at 22:02 GMT
Originally opened as ileitch/rapns#152


Having check_for_errors enabled is a huge performance hit. Would it be possible to read errors from the socket in such a way that doesn't block further sending? You would need to keep track of the order in which notifications were sent, because in the event of a disconnect and subsequent read from the socket, the failed notification might not be the last one sent and something that was previously marked delivered might need to be changed to failed.

PushSharp seems to handle this well: https://github.com/Redth/PushSharp/blob/master/PushSharp.Apple/ApplePushChannel.cs

APN are ringing several time

I have an issue with the gem when:

  • I send a notification "1" to a device
  • I don't read the notification on my device
  • I send another notification "2" to the same device
  • the application rings twice

When the device is not locked, it displayed the old notification as a banner first, then the new one.
I haven't been able to reproduce that by testing to send notifications to the same device, same certificate, but using another gem. Somehow old notifications are still triggering the ringtone and the notification center to display it again... any idea what is the issue?

Notification received on the phone but the rapns_notifications database still list the notification as not delivered

Issue by dc85 from Wednesday Jan 29, 2014 at 21:54 GMT
Originally opened as ileitch/rapns#198


I am using rapns to notify iOS devices of incoming chat messages when the app on the receiver is off. When the message is sent on the sender phone, I see the push notification pop up, but the database does not update the delivered status.

In rapns log it shows

1477 sent to xxxx (pid:20518)
Connected to feedback.sandbox.push.apple.com:2196 (pid:20518)

but in the database list 1477 delivered as false.

Now if I send a second message or if rapns.push gets called anywhere else in the app, it will send a push notification with this message again which why this is causing me a lot of problems.

The log for this behaviour is

[2014-01-29 16:33:42.545] [INFO] [2014-01-29 16:33:42] [app_name] 1475 sent to 567f512bd87864be86ddb1a5c0096f00fb86db03c29e45c08fbc44bc16d91654 (pid:20518)
[2014-01-29 16:33:43.519] [INFO] [2014-01-29 16:33:43] [app_name] Connected to feedback.sandbox.push.apple.com:2196 (pid:20518)
[2014-01-29 16:33:57.733] [INFO] [2014-01-29 16:33:57] [app_name] Started, 5 handlers. (pid:20515)
[2014-01-29 16:33:57.940] [INFO] [2014-01-29 16:33:57] [app_name] Started, 5 handlers. (pid:20515)
[2014-01-29 16:33:58.361] [INFO] [2014-01-29 16:33:58] [app_name] Connected to gateway.sandbox.push.apple.com:2195 (pid:20515)
[2014-01-29 16:33:58.370] [INFO] [2014-01-29 16:33:58] [app_name] Connected to gateway.sandbox.push.apple.com:2195 (pid:20515)
[2014-01-29 16:33:58.564] [INFO] [2014-01-29 16:33:58] [app_name] 1475 sent to 567f512bd87864be86ddb1a5c0096f00fb86db03c29e45c08fbc44bc16d91654 (pid:20515)
[2014-01-29 16:33:58.577] [INFO] [2014-01-29 16:33:58] [app_name] 1476 sent to 567f512bd87864be86ddb1a5c0096f00fb86db03c29e45c08fbc44bc16d91654 (pid:20515)
[2014-01-29 16:33:59.205] [INFO] [2014-01-29 16:33:59] [app_name] Connected to feedback.sandbox.push.apple.com:2196 (pid:20515)
[2014-01-29 16:40:50.114] [INFO] [2014-01-29 16:40:50] [app_name] Started, 5 handlers. (pid:20518)
[2014-01-29 16:40:50.115] [INFO] [2014-01-29 16:40:50] [app_name] Started, 5 handlers. (pid:20518)
[2014-01-29 16:40:50.709] [INFO] [2014-01-29 16:40:50] [app_name] Connected to gateway.sandbox.push.apple.com:2195 (pid:20518)
[2014-01-29 16:40:50.913] [INFO] [2014-01-29 16:40:50] [app_name] 1476 sent to 567f512bd87864be86ddb1a5c0096f00fb86db03c29e45c08fbc44bc16d91654 (pid:20518)
[2014-01-29 16:40:51.597] [INFO] [2014-01-29 16:40:51] [app_name] Connected to feedback.sandbox.push.apple.com:2196 (pid:20518)
[2014-01-29 16:41:35.677] [INFO] [2014-01-29 16:41:35] [app_name] Started, 5 handlers. (pid:20518)
[2014-01-29 16:41:35.678] [INFO] [2014-01-29 16:41:35] [app_name] Started, 5 handlers. (pid:20518)

Thanks in advance

fatal: deadlock detected

Issue by milindphirake from Wednesday Jan 22, 2014 at 17:46 GMT
Originally opened as ileitch/rapns#194


I implemented the push notifications and GCM notifications using this gem working great.

@ileitch

But i came across one strange issue. Sometimes my rails server goes into deadlock state.

Any Help on this will be great

I got the following log.

It cames when there is noting to push and we call "Rapns.push"

Log= >

Rapns::Notification Load (0.6ms) SELECT rapns_notifications.* FROM rapns_notifications WHERE (delivered = 0 AND failed = 0 AND (deliver_after IS NULL OR deliver_after < '2014-01-22 17:30:48')) AND (app_id IN (1,2,3,4))
=> {}

1.9.3-p484 :005 > Rapns.push

(0.3ms) SELECT COUNT() FROM rapns_apps
Rapns::App Load (0.2ms) SELECT rapns_apps.
FROM rapns_apps
Rapns::Notification Load (0.6ms) SELECT rapns_notifications.* FROM rapns_notifications WHERE (delivered = 0 AND failed = 0 AND (deliver_after IS NULL OR deliver_after < '2014-01-22 17:30:55')) AND (app_id IN (1,2,3,4))
fatal: deadlock detected
from /home/ubuntu/.rvm/gems/ruby-1.9.3-p484/gems/rapns-3.3.2/lib/rapns/daemon/delivery_handler.rb:21:in join' from /home/ubuntu/.rvm/gems/ruby-1.9.3-p484/gems/rapns-3.3.2/lib/rapns/daemon/delivery_handler.rb:21:instop'
from /home/ubuntu/.rvm/gems/ruby-1.9.3-p484/gems/rapns-3.3.2/lib/rapns/daemon/app_runner.rb:81:in map' from /home/ubuntu/.rvm/gems/ruby-1.9.3-p484/gems/rapns-3.3.2/lib/rapns/daemon/app_runner.rb:81:instop'
from /home/ubuntu/.rvm/gems/ruby-1.9.3-p484/gems/rapns-3.3.2/lib/rapns/daemon/app_runner.rb:46:in map' from /home/ubuntu/.rvm/gems/ruby-1.9.3-p484/gems/rapns-3.3.2/lib/rapns/daemon/app_runner.rb:46:instop'
from /home/ubuntu/.rvm/gems/ruby-1.9.3-p484/gems/rapns-3.3.2/lib/rapns/push.rb:15:in push' from (irb):5 from /home/ubuntu/.rvm/gems/ruby-1.9.3-p484/gems/railties-3.2.6/lib/rails/commands/console.rb:47:instart'
from /home/ubuntu/.rvm/gems/ruby-1.9.3-p484/gems/railties-3.2.6/lib/rails/commands/console.rb:8:in start' from /home/ubuntu/.rvm/gems/ruby-1.9.3-p484/gems/railties-3.2.6/lib/rails/commands.rb:41:in<top (required)>'
from script/rails:6:in require' from script/rails:6:in

'
1.9.3-p484 :006 >

How to ensure rpush is running on EC2/Elastic beanstalk

Hey, first off thank you for such a great gem, you saved me countless hours and it works great.

I am having issues ensuring that rpush is running on my EC2 instance. Is there a way to stop existing instances (i.e. rpush stop) so that I can stop and start the service on new push/periodically?

tldr; What is the best approach to ensure that it does not stop running.

Hot app update from app code

Hi,

I'm using RPush as a daemon from multiple Rails apps.

Each of them, eventually, can add a new APNS and GCM app to use. So, I'm creating a new Rpush apps, but the daemon is not aware of this. I've read this (https://github.com/rpush/rpush/wiki/Hot-App-Updates) but I'd like to automate the update process, so my question is: is there a way to tell the rpush daemon, from a rails app, to re-read the data from database?

Thank you

APNS feedback

Hi,

I'm using the reflection API to remove device tokens from my database, the intention is to respond to iOS app uninstalls or users disabling push.

However, it would appear that the method that I'm using is causing device tokens to be deleted if an APNS is not delivered regardless of the reason.

Below is the only method that I'm overriding in config/initializers/rpush.rb:

Called with a Rpush::Apns::Feedback instance when feedback is received

from the APNs that a notification has failed to be delivered.

Further notifications should not be sent to the device.

on.apns_feedback do |feedback|
d=Pushreg.find_by_devicetoken(feedback.device_token)
[*d].each do |registrationtodelete|
registrationtodelete.delete
registrationtodelete.save
end

end

Rapns::DeliveryError, Unable to deliver notification #, received error 8 (Invalid token)

Issue by mimikadze from Wednesday Sep 04, 2013 at 18:02 GMT
Originally opened as ileitch/rapns#159


We met the problem of delivery failures after message with invalid token was sent in the queue with valid ones. I mean not only that message fails, but the rest of messages with valid tokens. We could reproduce the issue working with our backend through TestFlight profiles instead of production profile of an app.

I've generated example logfile here http://pastebin.com/6B48raf8

As u see, we've got one invalid token message, but we don't recieve even next message, nevertheless nor error were received from APNS server.

We suppose we met an issue described in this post http://redth.info/the-problem-with-apples-push-notification-ser/ when Apple closes session after our damaged or expired device token, but rapns gem tries to send other enqueued messages the same way.

Hope, you'll find some workaround.

Remote Signals

Pull request by dei79 from Sunday Aug 12, 2012 at 16:04 GMT
Originally opened as ileitch/rapns#63


I added the option to send a signal to the daemon directly out of the rails application without the need to know where the daemon is running. For this this new model RemoteSignal was introduced. Just send a hup signal with the following code:

Rapns::RemoteSignal.push :key => :hup


dei79 included the following code: https://github.com/ileitch/rapns/pull/63/commits

Reflection on unhandled error codes

Hey guys, I wanted to start a new thread to discuss the best way to add a reflection method for unhandled HTTP error codes. That is, right now the notifications sent via http are only being marked as failed, and the exception can be caught on the "on.error" callback. But no easy way, a callback, to associate the notification failed on that exception.

The simplest way I suggest is to reuse the same "gcm_failed_to_recipient" reflection. The only problem is that both exceptions (exception message, I mean) and GCM error codes will be sent on the same "error" var.

Here I leave a gist with the piece of code to introduce this basic functionality https://gist.github.com/krakatoa/cef700dec83f5d6d6d0c

I'm not sure if that's the best place to add the reflection.. what do you think about this ?

how can i send push to multiple Rpush::Apns::App ?

In general, you have multiple certificate(e.g. appstore distribution, appstore adhoc) in a production server.

How can I send a push message to each "Rpush::Apns::App"?
Should I iterate each "Rpush::Apns::App" and create "Rpush::Apns::Notification"?
I think this is pretty inefficient method.

Could you tell me any solution?

Deprecation warning in Rails 3

When starting up, I get this notice:

DEPRECATION WARNING: railtie_name is deprecated and has no effect. (called from <top (required)> at /home/dave/dev/fadmin/trunk/config/application.rb:7)

uninitialized constant Rpush (NameError)

Upgraded from rapns to rpush

followed steps here

https://github.com/rpush/rpush/wiki/Moving-from-Rapns-to-Rpush

But the ruby server cannot initialize, log:

E, [2014-02-26T12:33:16.316722 #20180] ERROR -- : uninitialized constant Rpush (NameError)
/home/deployer/apps/app/releases/20140226171321/config/initializers/rpush.rb:3:in `<top (required)>'
/home/deployer/apps/app/shared/bundle/ruby/1.9.1/gems/railties-4.0.0/lib/rails/engine.rb:609:in `block (2 levels) in <class:Engine>'
/home/deployer/apps/app/shared/bundle/ruby/1.9.1/gems/railties-4.0.0/lib/rails/engine.rb:608:in `each'
/home/deployer/apps/app/shared/bundle/ruby/1.9.1/gems/railties-4.0.0/lib/rails/engine.rb:608:in `block in <class:Engine>'
/home/deployer/apps/app/shared/bundle/ruby/1.9.1/gems/railties-4.0.0/lib/rails/initializable.rb:30:in `instance_exec'
/home/deployer/apps/app/shared/bundle/ruby/1.9.1/gems/railties-4.0.0/lib/rails/initializable.rb:30:in `run'
/home/deployer/apps/app/shared/bundle/ruby/1.9.1/gems/railties-4.0.0/lib/rails/initializable.rb:55:in `block in run_initializers'

I deleted the initializers/rapns.rb and ran ruby g rpush and the rpush.rb was automatically added

Any idea what's happening?

Performance on Heroku

Issue by maxsz from Thursday Sep 26, 2013 at 12:55 GMT
Originally opened as ileitch/rapns#169


We recently started running rapns on heroku. Our goal is to send bursts of a few hundred thousand (possibly even more in the future) push messages per minute. Unfortunately the performance of our setup on heroku is really bad (like a few hundred pushes per minute). So I was thinking what would be the best option to improve the performance while still having the convenience of using heroku servers. Basically I think there are two options:

  1. Improve the rapns push-loop performance
  2. Support horizontal scaling

What are your thoughts on this?

Redis store implementation

Pull request by stevesng from Friday Aug 16, 2013 at 10:19 GMT
Originally opened as ileitch/rapns#155


An alternative store which implements all of ActiveRecord store's interface.

To use this Redis store, add/uncomment these in initializers/rapns.rb:

require 'connection_pool'
require 'rapns/daemon/store/redis_store'
Rapns::Notification.send(:include, Rapns::NotificationAsRedisObject)

Rapns.configure do |config|
...
config.store = :redis_store
config.redis_host = "localhost"
config.redis_port = 6379
config.number_of_connections = 5
config.connection_timeout = 1
config.stalled_notification_tolerence = 3600
...
end

To save a notification for sending:
notification.save_to_redis


stevesng included the following code: https://github.com/ileitch/rapns/pull/155/commits

fatal: deadlock detected

Issue by milindphirake from Wednesday Jan 22, 2014 at 17:47 GMT
Originally opened as ileitch/rapns#195


I implemented the push notifications and GCM notifications using this gem working great.

@ileitch

But i came across one strange issue. Sometimes my rails server goes into deadlock state.

Any Help on this will be great

I got the following log.

It cames when there is noting to push and we call "Rapns.push"

Log= >

Rapns::Notification Load (0.6ms) SELECT rapns_notifications.* FROM rapns_notifications WHERE (delivered = 0 AND failed = 0 AND (deliver_after IS NULL OR deliver_after < '2014-01-22 17:30:48')) AND (app_id IN (1,2,3,4))
=> {}

1.9.3-p484 :005 > Rapns.push

(0.3ms) SELECT COUNT() FROM rapns_apps
Rapns::App Load (0.2ms) SELECT rapns_apps.
FROM rapns_apps
Rapns::Notification Load (0.6ms) SELECT rapns_notifications.* FROM rapns_notifications WHERE (delivered = 0 AND failed = 0 AND (deliver_after IS NULL OR deliver_after < '2014-01-22 17:30:55')) AND (app_id IN (1,2,3,4))
fatal: deadlock detected
from /home/ubuntu/.rvm/gems/ruby-1.9.3-p484/gems/rapns-3.3.2/lib/rapns/daemon/delivery_handler.rb:21:in join' from /home/ubuntu/.rvm/gems/ruby-1.9.3-p484/gems/rapns-3.3.2/lib/rapns/daemon/delivery_handler.rb:21:instop'
from /home/ubuntu/.rvm/gems/ruby-1.9.3-p484/gems/rapns-3.3.2/lib/rapns/daemon/app_runner.rb:81:in map' from /home/ubuntu/.rvm/gems/ruby-1.9.3-p484/gems/rapns-3.3.2/lib/rapns/daemon/app_runner.rb:81:instop'
from /home/ubuntu/.rvm/gems/ruby-1.9.3-p484/gems/rapns-3.3.2/lib/rapns/daemon/app_runner.rb:46:in map' from /home/ubuntu/.rvm/gems/ruby-1.9.3-p484/gems/rapns-3.3.2/lib/rapns/daemon/app_runner.rb:46:instop'
from /home/ubuntu/.rvm/gems/ruby-1.9.3-p484/gems/rapns-3.3.2/lib/rapns/push.rb:15:in push' from (irb):5 from /home/ubuntu/.rvm/gems/ruby-1.9.3-p484/gems/railties-3.2.6/lib/rails/commands/console.rb:47:instart'
from /home/ubuntu/.rvm/gems/ruby-1.9.3-p484/gems/railties-3.2.6/lib/rails/commands/console.rb:8:in start' from /home/ubuntu/.rvm/gems/ruby-1.9.3-p484/gems/railties-3.2.6/lib/rails/commands.rb:41:in<top (required)>'
from script/rails:6:in require' from script/rails:6:in

'
1.9.3-p484 :006 >

apns slow

Issue by smoi from Friday Jan 31, 2014 at 14:55 GMT
Originally opened as ileitch/rapns#200


Hi,
yesterday I sent about 35k push to my iOS users and it took about 2 hours to send them, is there a way to speed-up it? maybe using more threads? Is this something related to the slowness of apple apns?

Rapns Worker stalls and not setting notifications as delivered

Issue by navied from Tuesday Nov 19, 2013 at 00:27 GMT
Originally opened as ileitch/rapns#179


I am having an issue with the rapns worker lately, It seems to suddenly stop working randomly and needs to be restarted, but what is worse is that the notifications that are sent after restarting the rapns worker is not being set as delivered and need to manually be set or the next time the worker is restarted it will resend them all again.

APNS runner doesn't restart on certificate or env change

Right now the app_runner can handle new APNS apps being added, but it doesn't handle cases where the APNS app was modified. For example, if the certificate was renewed (for instance, due to it expiring) or the environment was changed.

We needed this feature ourselves so I patched our copy of RPush to support it. Here's the commit if you'd like to consider pulling it in: https://github.com/gdeglin/rpush/commit/718eaca061260adbb20ff5d10173c624940a6504#diff-d41d8cd98f00b204e9800998ecf8427e

This commit changes the app_runner to reload any apps where the certificate or environment was changed. It also patches feedback_reciever to reflect tcp_connection_lost on an error in check_for_feedback instead of error. This is because the most common failure case here is the connection being lost due to the certificate being invalid or expiring and we need to know which app had the error so we can make sure the certificate gets updated.

Generate script is missing one of the migration templates

In a project with an old rapns installation, I attempted to upgrade to rpush (commit cbfdfd98d181c265f5e35e0206734f5bfb001969):

› rails g rpush                                                                                                                                                                              
[deprecated] I18n.enforce_available_locales will default to true in the future. If you really want to skip validation of your locale you can set I18n.enforce_available_locales = false to avoid this message.
      create  db/migrate/20140807185432_create_rapns_feedback.rb
      create  db/migrate/20140807185433_add_alert_is_json_to_rapns_notifications.rb
      create  db/migrate/20140807185434_add_app_to_rapns.rb
      create  db/migrate/20140807185435_create_rapns_apps.rb
      create  db/migrate/20140807185436_add_gcm.rb
      create  db/migrate/20140807185437_add_wpns.rb
      create  db/migrate/20140807185438_add_adm.rb
      create  db/migrate/20140807185439_rename_rapns_to_rpush.rb
      create  db/migrate/20140807185440_add_fail_after_to_rpush_notifications.rb
Could not find "add_processing_to_rpush_notifications.rb" in any of your source paths. Your current source paths are: 
/Users/eleos/axle/lib/templates/rpush
/Users/eleos/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/bundler/gems/rpush-cbfdfd98d181/lib/generators/templates

Is this migration still needed, or can the template copy be removed?

Error send notification GCM

[ERROR] Rpush::DeliveryError, Unable to deliver notification 25, received error (Failed to deliver to all recipients. Errors: InvalidRegistration.)
/Library/Ruby/Gems/2.0.0/gems/rpush-1.0.0/lib/rpush/daemon/gcm/delivery.rb:89:in handle_failures' /Library/Ruby/Gems/2.0.0/gems/rpush-1.0.0/lib/rpush/daemon/gcm/delivery.rb:55:inok'
/Library/Ruby/Gems/2.0.0/gems/rpush-1.0.0/lib/rpush/daemon/gcm/delivery.rb:35:in handle_response' /Library/Ruby/Gems/2.0.0/gems/rpush-1.0.0/lib/rpush/daemon/gcm/delivery.rb:23:inperform'
/Library/Ruby/Gems/2.0.0/gems/rpush-1.0.0/lib/rpush/daemon/dispatcher/http.rb:12:in dispatch' /Library/Ruby/Gems/2.0.0/gems/rpush-1.0.0/lib/rpush/daemon/dispatcher_loop.rb:44:indispatch'
/Library/Ruby/Gems/2.0.0/gems/rpush-1.0.0/lib/rpush/daemon/dispatcher_loop.rb:16:in block (2 levels) in start' /Library/Ruby/Gems/2.0.0/gems/rpush-1.0.0/lib/rpush/daemon/dispatcher_loop.rb:15:inloop'
/Library/Ruby/Gems/2.0.0/gems/rpush-1.0.0/lib/rpush/daemon/dispatcher_loop.rb:15:in `block in start'

this is my code
app = Rpush::Gcm::App.new
app.name = self.code
app.auth_key = self.android.api_key
app.connections = 1
app.save

devices.each do |device|
  n = Rpush::Gcm::Notification.new
  n.app = Rpush::Gcm::App.find_by_name(self.code)
  n.registration_ids = [device.identifier]
  n.data = {:message => params[:message]}
  n.data.merge!(:args=>params[:args]) if params[:args].present?
  n.save
end

Rpush.push

GCM failed to parse the JSON request

I'm getting GCM failed to parse the JSON request. Possibly an Rpush bug, please open an issue.
Error code is 400

Settings are as follows:

app = Rpush::Gcm::App.new
app.name = "testing"
app.auth_key = auth_key
app.connections = 1
app.save!

n = Rpush::Gcm::Notification.new
n.app = Rpush::Gcm::App.find_by_name("testing")
n.registration_ids = [token]
n.data = {message:"test message"}
n.delay_while_idle = true
n.expiry = Time.now + 3600
n.collapse_key = "test"
n.save!
Rpush.push

may I know what I did wrong? thanks...

Rapns daemon process get killed

Issue by McGar from Monday Dec 16, 2013 at 20:52 GMT
Originally opened as ileitch/rapns#188


I have a rapns process run as a daemon, but I found it always get killed in the next day after deploying with capistrano, when I try to start it by hand with "rapns env", it complains "Permission denied" for the log file generated by one of my customized daily loggers which is not for rapns, so I guess rapns get killed because of permission issue to access that log file.

So my question is why rapns tries to access the log file not for itself, I mean I have defined a custom logger for it.

new release?

Issue by Chelo from Thursday Jan 16, 2014 at 19:25 GMT
Originally opened as ileitch/rapns#193


Hey, how much time will take to get a new release with the WPNS?

Thanks :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.