apple_shove 2.0.2 → 2.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b119daa9b46ae843bed8fc8327dd77ac20189551
4
- data.tar.gz: f2a2c0b62cc2593f5f3a1cb3a239552cd3092028
3
+ metadata.gz: 09ae191145591b48d3b07274e4ddf795ae864f48
4
+ data.tar.gz: ffce5236fe7521703eb218f119218056e536554a
5
5
  SHA512:
6
- metadata.gz: 329d709e3ea8811764a41fe55928e3a2e48bb1a62262c920c15d3c8166c8901b2d92a3e2ec4c3bed360f92ee582b78e023804af41cf053932dbaaca3ab77e3e8
7
- data.tar.gz: fdad094d6ff2b8519ec200e2b4066b7a2a0d5f26bfce390370c389e7bcc5d061c450b780bcbf265a174837269a7267ffa0948370e8edf26594c86fb77ac2e5a4
6
+ metadata.gz: 3a5bfdb8a2e81a9da2e13e393aa2b015ae671470faba143ab2c4eec5f85b11e4af3b7f4670b5b36855a6625769b22ab70887195670defa4436cc9058db004939
7
+ data.tar.gz: a75ded949908014b09871ee283dfcbe69ccb1b005bfa2b3129b118a6589b1a2365b2ed562adfee1651c09616132315fbaba4e423db371bcfb213decdad11d228
@@ -3,9 +3,9 @@ require 'openssl'
3
3
  module AppleShove
4
4
  module APNS
5
5
  class Connection
6
-
6
+
7
7
  attr_reader :last_used
8
-
8
+
9
9
  def initialize(host, port, p12_string)
10
10
  @host = host
11
11
  @port = port
@@ -22,7 +22,7 @@ module AppleShove
22
22
 
23
23
  def disconnect
24
24
  @ssl_sock.close if @ssl_sock
25
-
25
+
26
26
  begin
27
27
  @sock.close if @sock
28
28
  rescue IOError
@@ -35,8 +35,12 @@ module AppleShove
35
35
  connect
36
36
  end
37
37
 
38
+ def safe_last_used
39
+ @last_used || Time.at(0)
40
+ end
41
+
38
42
  private
39
-
43
+
40
44
  def connect
41
45
  @p12 ||= OpenSSLHelper.pkcs12_from_pem(@p12_string)
42
46
  context = ::OpenSSL::SSL::SSLContext.new
@@ -47,14 +51,14 @@ module AppleShove
47
51
  @sock.setsockopt(Socket::SOL_SOCKET, Socket::SO_KEEPALIVE, true)
48
52
  @ssl_sock = ::OpenSSL::SSL::SSLSocket.new(@sock, context)
49
53
  @ssl_sock.sync = true
50
-
54
+
51
55
  @ssl_sock.connect
52
56
  end
53
-
57
+
54
58
  def connected?
55
59
  @sock && @ssl_sock
56
60
  end
57
-
61
+
58
62
  end
59
63
  end
60
64
  end
@@ -33,7 +33,7 @@ module AppleShove
33
33
  message = notification.binary_message
34
34
 
35
35
  begin
36
- if @last_used && Time.now - @last_used > CONFIG[:reconnect_timer] * 60
36
+ if @last_used && Time.now - safe_last_used > CONFIG[:reconnect_timer] * 60
37
37
  Logger.info("refreshing connection", self, notification)
38
38
  reconnect
39
39
  end
@@ -1,21 +1,21 @@
1
1
  module AppleShove
2
2
  class Demultiplexer
3
-
3
+
4
4
  def initialize(opts = {})
5
5
  unless opts[:max_apns_connections]
6
6
  raise ArgumentError, 'max_apns_connections must be specified'
7
7
  end
8
-
8
+
9
9
  @max_connections = opts[:max_apns_connections].to_i
10
10
 
11
11
  @connections = {}
12
12
  @queue = NotificationQueue.new(CONFIG[:redis_key])
13
13
  end
14
-
14
+
15
15
  def start
16
16
 
17
17
  while true
18
-
18
+
19
19
  if notification = @queue.get
20
20
  conn = get_connection(notification)
21
21
  conn.pending_notifications += 1
@@ -23,38 +23,38 @@ module AppleShove
23
23
  else
24
24
  sleep 1
25
25
  end
26
-
26
+
27
27
  end
28
-
28
+
29
29
  end
30
30
 
31
31
  private
32
32
 
33
33
  def get_connection(notification)
34
34
  key = APNS::NotifyConnection.generate_name(notification.p12, notification.sandbox)
35
- connection = @connections[key]
35
+ connection = @connections[key]
36
36
 
37
37
  unless connection
38
38
  retire_oldest_connection if @connections.count >= @max_connections
39
39
 
40
40
  connection = APNS::NotifyConnection.new notification.p12, notification.sandbox
41
41
  @connections[key] = connection
42
- Logger.info "created connection to APNS (#{@connections.count} total)", connection
42
+ Logger.info "created connection to APNS (#{@connections.count} total)", connection
43
43
  end
44
-
44
+
45
45
  connection
46
46
  end
47
-
47
+
48
48
  def retire_oldest_connection
49
- if oldest = @connections.min_by { |_k, v| v.last_used }
49
+ if oldest = @connections.min_by { |_k, v| v.safe_last_used }
50
50
  key, conn = oldest[0], oldest[1]
51
51
  conn_name = conn.name
52
52
  @connections.delete key
53
53
  conn.shutdown
54
-
54
+
55
55
  Logger.info "destroyed connection to APNS (#{@connections.count} total)", conn_name
56
56
  end
57
57
  end
58
-
58
+
59
59
  end
60
60
  end
@@ -1,3 +1,3 @@
1
1
  module AppleShove
2
- VERSION = "2.0.2"
2
+ VERSION = "2.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apple_shove
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Taylor Boyko