resque-aps 0.9.11 → 0.9.12
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY.md +4 -0
- data/lib/resque_aps.rb +2 -2
- data/lib/resque_aps/application.rb +8 -6
- data/lib/resque_aps/version.rb +1 -1
- data/test/application_test.rb +11 -1
- data/test/resque-web_test.rb +1 -1
- data/test/test_helper.rb +1 -0
- metadata +1 -1
data/HISTORY.md
CHANGED
data/lib/resque_aps.rb
CHANGED
@@ -79,7 +79,7 @@ module Resque
|
|
79
79
|
end
|
80
80
|
|
81
81
|
def enqueue_aps_application(application_name, override = false)
|
82
|
-
count_apps = aps_applications_queued_count(application_name)
|
82
|
+
count_apps = aps_applications_queued_count(application_name).to_i
|
83
83
|
count_not = aps_notification_count_for_application(application_name)
|
84
84
|
if override || count_apps <= 0 || (count_apps < aps_application_job_limit && (count_not > aps_queue_size_upper && count_not % (aps_queue_size_upper / 10) == 0))
|
85
85
|
enqueue(Resque::Plugins::Aps::Application, application_name)
|
@@ -88,7 +88,7 @@ module Resque
|
|
88
88
|
end
|
89
89
|
|
90
90
|
def dequeue_aps_application(application_name)
|
91
|
-
redis.decr(aps_application_queued_key(application_name)) if aps_applications_queued_count(application_name) > 0
|
91
|
+
redis.decr(aps_application_queued_key(application_name)) if aps_applications_queued_count(application_name).to_i > 0
|
92
92
|
end
|
93
93
|
|
94
94
|
def enqueue_aps(application_name, notification)
|
@@ -33,18 +33,20 @@ module Resque
|
|
33
33
|
app.before_aps_write n
|
34
34
|
begin
|
35
35
|
n.batch_id = count + 1
|
36
|
-
n.expiry =
|
36
|
+
n.expiry = Time.now.utc.to_i + 3600
|
37
37
|
socket.write(n.formatted)
|
38
38
|
app.after_aps_write n
|
39
39
|
count += 1
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
40
|
+
# resp = socket.read
|
41
|
+
# if resp && resp != ""
|
42
|
+
# # logger.error "Failure response: #{resp.inspect}" if logger
|
43
|
+
# logger.error "Failure response: #{resp.bytes.to_a.map{|i| i.to_s(16)}.join}" if logger
|
44
|
+
# break
|
45
|
+
# end
|
44
46
|
rescue
|
45
47
|
logger.error Application.application_exception($!, app_name) if logger
|
46
48
|
app.failed_aps_write n, $!
|
47
|
-
logger.error "Sent #{count} notifications before failure." if logger
|
49
|
+
logger.error "#{$!}: Sent #{count} notifications before failure." if logger
|
48
50
|
Resque.enqueue_aps(app_name, n)
|
49
51
|
break
|
50
52
|
end
|
data/lib/resque_aps/version.rb
CHANGED
data/test/application_test.rb
CHANGED
@@ -19,10 +19,11 @@ context "Resque::Plugins::Aps::Application" do
|
|
19
19
|
end
|
20
20
|
|
21
21
|
test "can perform" do
|
22
|
-
n = Resque::Plugins::Aps::Notification.new('application_name' => 'TestApp', 'device_token' => '
|
22
|
+
n = Resque::Plugins::Aps::Notification.new('application_name' => 'TestApp', 'device_token' => '3ECA0F9A3405B980A88A61A1556AF8B7F1DF5F7F109E1476A781E8220C4FE561', 'payload' => '{"aps": { "alert": "hello"}}')
|
23
23
|
assert Resque.enqueue_aps('TestApp', n)
|
24
24
|
Resque.create_aps_application('TestApp', File.dirname(__FILE__) + "/../test-dev.pem", nil)
|
25
25
|
Resque::Plugins::Aps::Application.perform('TestApp')
|
26
|
+
assert_equal 0, Resque.aps_notification_count_for_application('TestApp')
|
26
27
|
end
|
27
28
|
|
28
29
|
context "ApplicationWithHooks" do
|
@@ -52,10 +53,19 @@ context "Resque::Plugins::Aps::Application" do
|
|
52
53
|
end
|
53
54
|
|
54
55
|
test "can perform with logging hooks" do
|
56
|
+
n = Resque::Plugins::Aps::Notification.new('application_name' => 'TestApp', 'device_token' => '3ECA0F9A3405B980A88A61A1556AF8B7F1DF5F7F109E1476A781E8220C4FE561', 'payload' => '{"aps": { "alert": "hello"}}')
|
57
|
+
assert Resque.enqueue_aps('TestApp', n)
|
58
|
+
Resque.create_aps_application('TestApp', File.dirname(__FILE__) + "/../test-dev.pem", nil)
|
59
|
+
Resque::Plugins::Aps::Application.perform('TestApp')
|
60
|
+
assert_equal 0, Resque.aps_notification_count_for_application('TestApp')
|
61
|
+
end
|
62
|
+
|
63
|
+
test "can perform with failure logging hooks" do
|
55
64
|
n = Resque::Plugins::Aps::Notification.new('application_name' => 'TestApp', 'device_token' => 'aihdf08u2402hbdfquhiwr', 'payload' => '{"aps": { "alert": "hello"}}')
|
56
65
|
assert Resque.enqueue_aps('TestApp', n)
|
57
66
|
Resque.create_aps_application('TestApp', File.dirname(__FILE__) + "/../test-dev.pem", nil)
|
58
67
|
Resque::Plugins::Aps::Application.perform('TestApp')
|
68
|
+
assert_equal 0, Resque.aps_notification_count_for_application('TestApp')
|
59
69
|
end
|
60
70
|
end
|
61
71
|
end
|
data/test/resque-web_test.rb
CHANGED
@@ -29,7 +29,7 @@ context "on GET to /aps/some_ivar_application" do
|
|
29
29
|
setup do
|
30
30
|
Resque.redis.flushall
|
31
31
|
Resque.create_aps_application(:some_ivar_application, nil, nil)
|
32
|
-
n = Resque::Plugins::Aps::Notification.new('application_name' => 'some_ivar_application', 'device_token' => '
|
32
|
+
n = Resque::Plugins::Aps::Notification.new('application_name' => 'some_ivar_application', 'device_token' => '3ECA0F9A3405B980A88A61A1556AF8B7F1DF5F7F109E1476A781E8220C4FE561', 'payload' => '{"aps": { "alert": "hello"}}')
|
33
33
|
assert Resque.enqueue_aps(:some_ivar_application, n)
|
34
34
|
assert Resque.enqueue_aps(:some_ivar_application, n)
|
35
35
|
assert Resque.enqueue_aps(:some_ivar_application, n)
|
data/test/test_helper.rb
CHANGED