rapns 0.2.0 → 0.2.1
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.
- data/lib/rapns/daemon/delivery_handler.rb +1 -1
- data/lib/rapns/daemon/delivery_queue.rb +21 -14
- data/lib/rapns/daemon/feeder.rb +1 -1
- data/lib/rapns/daemon.rb +1 -1
- data/lib/rapns/version.rb +1 -1
- data/spec/rapns/daemon/delivery_handler_spec.rb +3 -3
- data/spec/rapns/daemon/feeder_spec.rb +3 -3
- data/spec/rapns/daemon_spec.rb +5 -0
- metadata +2 -2
@@ -1,9 +1,10 @@
|
|
1
1
|
module Rapns
|
2
2
|
module Daemon
|
3
3
|
class DeliveryQueue
|
4
|
-
def initialize
|
4
|
+
def initialize(num_handlers)
|
5
|
+
@num_handlers = num_handlers
|
5
6
|
@queue = Queue.new
|
6
|
-
@
|
7
|
+
@feeder_threads = []
|
7
8
|
@mutex = Mutex.new
|
8
9
|
end
|
9
10
|
|
@@ -15,23 +16,29 @@ module Rapns
|
|
15
16
|
@queue.pop
|
16
17
|
end
|
17
18
|
|
18
|
-
def
|
19
|
+
def handler_available
|
19
20
|
@mutex.synchronize do
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
21
|
+
signal_feeder if handler_available?
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def handler_available?
|
26
|
+
@queue.size < @num_handlers
|
27
|
+
end
|
28
|
+
|
29
|
+
def signal_feeder
|
30
|
+
begin
|
31
|
+
t = @feeder_threads.shift
|
32
|
+
t.wakeup if t
|
33
|
+
rescue ThreadError
|
34
|
+
retry
|
28
35
|
end
|
29
36
|
end
|
30
37
|
|
31
|
-
def
|
38
|
+
def wait_for_available_handler
|
32
39
|
Thread.exclusive do
|
33
|
-
if @queue.size
|
34
|
-
@
|
40
|
+
if @queue.size >= @num_handlers
|
41
|
+
@feeder_threads << Thread.current
|
35
42
|
Thread.stop
|
36
43
|
end
|
37
44
|
end
|
data/lib/rapns/daemon/feeder.rb
CHANGED
@@ -20,7 +20,7 @@ module Rapns
|
|
20
20
|
Rapns::Daemon.delivery_queue.push(notification)
|
21
21
|
end
|
22
22
|
|
23
|
-
Rapns::Daemon.delivery_queue.
|
23
|
+
Rapns::Daemon.delivery_queue.wait_for_available_handler
|
24
24
|
rescue ActiveRecord::StatementInvalid, *ADAPTER_ERRORS => e
|
25
25
|
Rapns::Daemon.logger.error(e)
|
26
26
|
reconnect
|
data/lib/rapns/daemon.rb
CHANGED
data/lib/rapns/version.rb
CHANGED
@@ -3,7 +3,7 @@ require "spec_helper"
|
|
3
3
|
describe Rapns::Daemon::DeliveryHandler do
|
4
4
|
before do
|
5
5
|
@notification = Rapns::Notification.create!(:device_token => "a" * 64)
|
6
|
-
Rapns::Daemon.stub(:delivery_queue).and_return(Rapns::Daemon::DeliveryQueue.new)
|
6
|
+
Rapns::Daemon.stub(:delivery_queue).and_return(Rapns::Daemon::DeliveryQueue.new(1))
|
7
7
|
Rapns::Daemon.delivery_queue.push(@notification)
|
8
8
|
@connection = mock("Connection", :connect => nil, :write => nil)
|
9
9
|
Rapns::Daemon::Connection.stub(:new).and_return(@connection)
|
@@ -59,8 +59,8 @@ describe Rapns::Daemon::DeliveryHandler do
|
|
59
59
|
@delivery_handler.send(:handle_next_notification)
|
60
60
|
end
|
61
61
|
|
62
|
-
it "should
|
63
|
-
Rapns::Daemon.delivery_queue.should_receive(:
|
62
|
+
it "should notify the delivery queue a handler is now available" do
|
63
|
+
Rapns::Daemon.delivery_queue.should_receive(:handler_available)
|
64
64
|
@delivery_handler.send(:handle_next_notification)
|
65
65
|
end
|
66
66
|
|
@@ -6,7 +6,7 @@ describe Rapns::Daemon::Feeder do
|
|
6
6
|
@notification = Rapns::Notification.create!(:device_token => "a" * 64)
|
7
7
|
@logger = mock("Logger", :info => nil, :error => nil, :warn => nil)
|
8
8
|
Rapns::Daemon.stub(:logger).and_return(@logger)
|
9
|
-
@queue = mock(:push => nil, :
|
9
|
+
@queue = mock(:push => nil, :wait_for_available_handler => nil)
|
10
10
|
Rapns::Daemon.stub(:delivery_queue).and_return(@queue)
|
11
11
|
Rapns::Daemon.stub(:configuration => mock("Configuration", :poll => 2))
|
12
12
|
end
|
@@ -52,8 +52,8 @@ describe Rapns::Daemon::Feeder do
|
|
52
52
|
Rapns::Daemon::Feeder.enqueue_notifications
|
53
53
|
end
|
54
54
|
|
55
|
-
it "should wait for
|
56
|
-
Rapns::Daemon.delivery_queue.should_receive(:
|
55
|
+
it "should wait for a delivery handler to become available" do
|
56
|
+
Rapns::Daemon.delivery_queue.should_receive(:wait_for_available_handler)
|
57
57
|
Rapns::Daemon::Feeder.enqueue_notifications
|
58
58
|
end
|
59
59
|
|
data/spec/rapns/daemon_spec.rb
CHANGED
@@ -60,6 +60,11 @@ describe Rapns::Daemon, "when starting" do
|
|
60
60
|
Rapns::Daemon.start("development", {})
|
61
61
|
end
|
62
62
|
|
63
|
+
it "should initialize the delivery queue with the number of connection as its signal point" do
|
64
|
+
Rapns::Daemon::DeliveryQueue.should_receive(:new).with(3)
|
65
|
+
Rapns::Daemon.start("development", {})
|
66
|
+
end
|
67
|
+
|
63
68
|
it "should make the connection pool accessible" do
|
64
69
|
Rapns::Daemon.start("development", {})
|
65
70
|
Rapns::Daemon.connection_pool.should == @connection_pool
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rapns
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-10-
|
12
|
+
date: 2011-10-14 00:00:00.000000000Z
|
13
13
|
dependencies: []
|
14
14
|
description: Easy to use library for Apple's Push Notification Service with Rails
|
15
15
|
3
|