banjo-apn_sender 2.2.5 → 2.3.0

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: 407025f567dc38fd577506d8a0981004a3004506
4
- data.tar.gz: e9ef670c1bdf0e72b78921bfbfc9c7b70fae9801
3
+ metadata.gz: a634620bc1103f8cf7e5dc05cccc110f9304c58e
4
+ data.tar.gz: 12caed86038b507c3d566462eb242b18e0c65585
5
5
  SHA512:
6
- metadata.gz: b504b0940e92752a3bd6eca48797124dc066c4150e3d899f88d975264cd85758e41bbdb2a1d2e188cb3955c8173492c8ff4aa67c815df67b0bdaa4ac4de4fef9
7
- data.tar.gz: 26a88177dccce59a37b2360140e82f25555007ba882d988dba28000ff0e4158685942d095aea43b9119ee74cc2a9c2e758ceeb4d54ebd87f3749b2b73a5f5a7d
6
+ metadata.gz: d7c42f2e5f6c2a5ec184223235d1f885611526c1c99c9e06057f5125346a9d0dc48d2cd83f778d9a8c4528395ba9e44cd4609079862ace44ea22bf479dcd59ee
7
+ data.tar.gz: 27d2269b1aca8c496179d34456ced200560428cb7eeb8622be1ad877aec92488dfe86564b9a87dd20f7484ecc1af27b0f0d7699d64517e036a137304b296871a
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- banjo-apn_sender (2.1.1)
4
+ banjo-apn_sender (2.2.5)
5
5
  multi_json
6
6
 
7
7
  GEM
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{banjo-apn_sender}
8
- s.version = "2.2.5"
8
+ s.version = "2.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = [%q{Kali Donovan}, %q{KW Justin Leung}]
@@ -1,11 +1,14 @@
1
1
  class APN::Connection
2
2
  include APN::Base
3
3
  TIMES_TO_RETRY_SOCKET_ERROR = 2
4
+ IDLE_RECONNECTION_INTERVAL = 120
4
5
 
5
6
  @production_senders = Hash.new
6
7
  @sandbox_senders = Hash.new
7
8
  @enterprise_semaphore = Mutex.new
8
9
 
10
+ @production_last_accesses = Hash.new
11
+ @sandbox_last_accesses = Hash.new
9
12
 
10
13
  def push_fifo(env, token)
11
14
  @fifos[env] <<= token
@@ -35,9 +38,7 @@ class APN::Connection
35
38
 
36
39
  # Try reestablishing the connection
37
40
  if (retries += 1) <= TIMES_TO_RETRY_SOCKET_ERROR
38
- teardown_connection
39
- sleep 1
40
- setup_connection
41
+ reconnect
41
42
  retry
42
43
  end
43
44
 
@@ -46,20 +47,38 @@ class APN::Connection
46
47
  end
47
48
  end
48
49
 
50
+ def reconnect
51
+ teardown_connection
52
+ sleep 1
53
+ setup_connection
54
+ end
55
+
49
56
  def self.current(sandbox = false, enterprise = false)
50
57
  thread_id = Thread.current.object_id
58
+ epoch = Time.now.to_i
51
59
 
52
60
  # Use only 1 single thread for internal enterprise cert
53
- if enterprise
54
- if sandbox
55
- @sandbox_enterprise_sender ||= new(worker_count: 1, sandbox: 1, verbose: 1, enterprise: 1)
56
- else
57
- @production_enterprise_sender ||= new(worker_count: 1, verbose: 1, enterprise: 1)
58
- end
61
+ if enterprise && !sandbox
62
+ if @enterprise_sender && (epoch - @enterprise_last_access) > IDLE_RECONNECTION_INTERVAL
63
+ @enterprise_sender.reconnect
64
+ end
65
+
66
+ @enterprise_last_access = epoch
67
+ @enterprise_sender ||= new(worker_count: 1, verbose: 1, enterprise: 1)
59
68
  else
60
69
  if sandbox
70
+ if @sandbox_senders[thread_id] && (epoch - @sandbox_last_accesses[thread_id]) > IDLE_RECONNECTION_INTERVAL
71
+ @sandbox_senders[thread_id].reconnect
72
+ end
73
+
74
+ @sandbox_last_accesses[thread_id] = epoch
61
75
  @sandbox_senders[thread_id] ||= new(worker_count: 1, sandbox: 1, verbose: 1)
62
76
  else
77
+ if @production_senders[thread_id] && (epoch - @production_last_accesses[thread_id]) > IDLE_RECONNECTION_INTERVAL
78
+ @production_senders[thread_id].reconnect
79
+ end
80
+
81
+ @production_last_accesses[thread_id] = epoch
63
82
  @production_senders[thread_id] ||= new(worker_count: 1, verbose: 1)
64
83
  end
65
84
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: banjo-apn_sender
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.5
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kali Donovan