banjo-apn_sender 2.2.5 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/apn_sender.gemspec +1 -1
- data/lib/apn/connection.rb +28 -9
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a634620bc1103f8cf7e5dc05cccc110f9304c58e
|
4
|
+
data.tar.gz: 12caed86038b507c3d566462eb242b18e0c65585
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d7c42f2e5f6c2a5ec184223235d1f885611526c1c99c9e06057f5125346a9d0dc48d2cd83f778d9a8c4528395ba9e44cd4609079862ace44ea22bf479dcd59ee
|
7
|
+
data.tar.gz: 27d2269b1aca8c496179d34456ced200560428cb7eeb8622be1ad877aec92488dfe86564b9a87dd20f7484ecc1af27b0f0d7699d64517e036a137304b296871a
|
data/Gemfile.lock
CHANGED
data/apn_sender.gemspec
CHANGED
@@ -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.
|
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}]
|
data/lib/apn/connection.rb
CHANGED
@@ -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
|
-
|
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
|
55
|
-
@
|
56
|
-
|
57
|
-
|
58
|
-
|
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
|