Skip to content

Commit bb6e645

Browse files
Merge pull request #31 from Papercloud/fix/houston-threading
Fix/houston threading
2 parents 7ed6898 + a420cc1 commit bb6e645

File tree

5 files changed

+11
-31
lines changed

5 files changed

+11
-31
lines changed

README.md

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,6 @@ wwtd
5353
## APNS providers
5454
By default, we use [Houston](https://github.com/nomad/houston/) to deliver push notifications via APNS from the server.
5555

56-
The initialiser for `notify_user` contains the following configuration when delivering via Houston:
57-
```
58-
# Number of connections Houston will maintain to APNS:
59-
config.connection_pool_size = 3
60-
61-
# Time in seconds Houston will wait for a free connection before failing:
62-
config.connection_pool_timeout = 300
63-
```
64-
65-
We maintain persistent connections to APNS via background workers, and these values will allow you to configure how many connections the workers maintain, as well as the amount of time to wait for an idle connection before timing out.
66-
6756
You also need to provide exported versions of your push notification certificate and key as .pem files, these instructions come from the [APN on Rails](https://github.com/PRX/apn_on_rails) project on how to do that:
6857

6958
Once you have the certificate from Apple for your application, export your key

app/models/notify_user/apn_connection.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
module NotifyUser
22
class APNConnection
33

4+
POOL = ConnectionPool.new(size: ENV['APNS_CONNECTION_POOL_SIZE'] || 1, timeout: ENV['APNS_CONNECTION_TIMEOUT'] || 30) {
5+
APNConnection.new
6+
}
7+
48
def initialize
59
connection
610
end

app/models/notify_user/apns.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ module NotifyUser
55
class Apns < Push
66
NO_ERROR = -42
77
INVALID_TOKEN_ERROR = 8
8-
CONNECTION = APNConnection.new
98

10-
attr_accessor :push_options
9+
attr_accessor :push_options, :apn_connection
1110

1211
def initialize(notifications, devices, options)
1312
super(notifications, devices, options)
@@ -17,19 +16,22 @@ def initialize(notifications, devices, options)
1716
end
1817

1918
def push
20-
send_notifications
19+
APNConnection::POOL.with do |apn_conn|
20+
@apn_connection = apn_conn
21+
send_notifications
22+
end
2123
end
2224

2325
private
2426

2527
attr_accessor :devices
2628

2729
def connection
28-
CONNECTION.connection
30+
apn_connection.connection
2931
end
3032

3133
def reset_connection
32-
CONNECTION.reset
34+
apn_connection.reset
3335
end
3436

3537
def setup_options

lib/generators/notify_user/install/templates/initializer.rb

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,4 @@
1414

1515
# Provider for APNS:
1616
config.apns_provider = :houston
17-
18-
# Number of connections Houston will maintain to APNS:
19-
config.connection_pool_size = 3
20-
21-
# Time in seconds Houston will wait for a free connection before failing:
22-
config.connection_pool_timeout = 300
23-
2417
end

lib/notify_user.rb

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,6 @@ module NotifyUser
2020
mattr_accessor :apns_provider
2121
@@apns_provider = nil
2222

23-
# Number of connections Houston will maintain to APNS:
24-
mattr_accessor :connection_pool_size
25-
@@connection_pool_size = nil
26-
27-
# Time in seconds Houston will wait for a free connection before failing:
28-
mattr_accessor :connection_pool_timeout
29-
@@connection_pool_timeout = nil
30-
3123
# Used to set up NotifyUser from the initializer.
3224
def self.setup
3325
yield self

0 commit comments

Comments
 (0)