resque-aps 0.9.14 → 0.9.15
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/HISTORY.md +6 -0
- data/Rakefile +3 -3
- data/lib/resque/plugins/aps.rb +6 -31
- data/lib/resque/plugins/aps/application.rb +57 -0
- data/lib/resque/plugins/aps/server/views/aps_applications.erb +1 -1
- data/lib/resque/plugins/aps/version.rb +1 -1
- data/test/resque-web_test.rb +1 -1
- metadata +41 -37
data/HISTORY.md
CHANGED
data/Rakefile
CHANGED
|
@@ -23,7 +23,7 @@ begin
|
|
|
23
23
|
puts "gem install jeweler"
|
|
24
24
|
end
|
|
25
25
|
|
|
26
|
-
require '
|
|
26
|
+
require 'resque/plugins/aps/version'
|
|
27
27
|
|
|
28
28
|
Jeweler::Tasks.new do |gemspec|
|
|
29
29
|
gemspec.name = "resque-aps"
|
|
@@ -36,8 +36,8 @@ begin
|
|
|
36
36
|
gemspec.authors = ["Ashley Martens"]
|
|
37
37
|
gemspec.version = Resque::Plugins::Aps::Version
|
|
38
38
|
|
|
39
|
-
gemspec.add_dependency "redis", ">= 1.0.7"
|
|
40
|
-
gemspec.add_dependency "resque", ">= 1.5.0"
|
|
39
|
+
# gemspec.add_dependency "redis", ">= 1.0.7"
|
|
40
|
+
# gemspec.add_dependency "resque", ">= 1.5.0"
|
|
41
41
|
gemspec.add_development_dependency "jeweler"
|
|
42
42
|
gemspec.add_development_dependency "mocha"
|
|
43
43
|
gemspec.add_development_dependency "rack-test"
|
data/lib/resque/plugins/aps.rb
CHANGED
|
@@ -61,34 +61,16 @@ module Resque
|
|
|
61
61
|
def aps_application_job_limit
|
|
62
62
|
@aps_application_job_limit ||= 5
|
|
63
63
|
end
|
|
64
|
-
|
|
65
|
-
def aps_applications_queued_count(application_name)
|
|
66
|
-
redis.get(aps_application_queued_key(application_name)) || 0
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
def enqueue_aps_application(application_name, override = false)
|
|
70
|
-
count_apps = aps_applications_queued_count(application_name).to_i
|
|
71
|
-
count_not = aps_notification_count_for_application(application_name)
|
|
72
|
-
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))
|
|
73
|
-
enqueue(Resque::Plugins::Aps::Application, application_name)
|
|
74
|
-
redis.incr(aps_application_queued_key(application_name))
|
|
75
|
-
end
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
def dequeue_aps_application(application_name)
|
|
79
|
-
redis.decr(aps_application_queued_key(application_name)) if aps_applications_queued_count(application_name).to_i > 0
|
|
80
|
-
end
|
|
81
|
-
|
|
64
|
+
|
|
82
65
|
def enqueue_aps(application_name, notification)
|
|
83
66
|
redis.rpush(aps_application_queue_key(application_name), encode(notification.to_hash))
|
|
84
|
-
|
|
67
|
+
Resque::Plugins::Aps::Application.new('name' => application_name).enqueue
|
|
85
68
|
true
|
|
86
69
|
end
|
|
87
70
|
|
|
88
71
|
def dequeue_aps(application_name)
|
|
89
72
|
h = decode(redis.lpop(aps_application_queue_key(application_name)))
|
|
90
|
-
|
|
91
|
-
nil
|
|
73
|
+
h ? Resque::Plugins::Aps::Notification.new(h) : nil
|
|
92
74
|
end
|
|
93
75
|
|
|
94
76
|
# Returns the number of queued notifications for a given application
|
|
@@ -99,11 +81,7 @@ module Resque
|
|
|
99
81
|
# Returns an array of queued notifications for the given application
|
|
100
82
|
def aps_notifications_for_application(application_name, start = 0, count = 1)
|
|
101
83
|
r = redis.lrange(aps_application_queue_key(application_name), start, count)
|
|
102
|
-
|
|
103
|
-
r.map { |h| Resque::Plugins::Aps::Notification.new(decode(h)) }
|
|
104
|
-
else
|
|
105
|
-
[]
|
|
106
|
-
end
|
|
84
|
+
r ? r.map { |h| Resque::Plugins::Aps::Notification.new(decode(h)) } : []
|
|
107
85
|
end
|
|
108
86
|
|
|
109
87
|
def create_aps_application(name, cert_file, cert_passwd = nil)
|
|
@@ -113,17 +91,14 @@ module Resque
|
|
|
113
91
|
|
|
114
92
|
def aps_application(name)
|
|
115
93
|
h = decode(redis.get(aps_application_key(name)))
|
|
116
|
-
|
|
117
|
-
nil
|
|
94
|
+
h ? Resque::Plugins::Aps::Application.new(h) : nil
|
|
118
95
|
end
|
|
119
96
|
|
|
120
97
|
# Returns an array of applications based on start and count
|
|
121
98
|
def aps_application_names(start = 0, count = 1)
|
|
122
99
|
a = redis.smembers(:aps_applications)
|
|
123
100
|
return a if count == 0
|
|
124
|
-
|
|
125
|
-
return [] unless ret
|
|
126
|
-
ret
|
|
101
|
+
a[start..(start + count)] || []
|
|
127
102
|
end
|
|
128
103
|
|
|
129
104
|
# Returns the number of application queues
|
|
@@ -177,6 +177,63 @@ module Resque
|
|
|
177
177
|
logger.error("ResqueAps[read_failed]: Bad data on the socket (#{name})") if logger
|
|
178
178
|
end
|
|
179
179
|
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
def queued_count
|
|
185
|
+
(redis.get(Resque.aps_application_queued_key(name)) || 0).to_i
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
def lock_key
|
|
189
|
+
@lock_key ||= "#{Resque.aps_application_key(name)}:lock"
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
def redis
|
|
193
|
+
Resque.redis
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
def acquire_lock
|
|
197
|
+
if redis.setnx(lock_key, Time.now.utc.to_i + 1)
|
|
198
|
+
true
|
|
199
|
+
elsif Time.at(redis.get(lock_key).to_i) > Time.now
|
|
200
|
+
delete_lock
|
|
201
|
+
acquire_lock
|
|
202
|
+
else
|
|
203
|
+
false
|
|
204
|
+
end
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
def delete_lock
|
|
208
|
+
redis.del(lock_key)
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
def enqueue(override = false)
|
|
212
|
+
count_apps = 0
|
|
213
|
+
count_not = 0
|
|
214
|
+
locked = false
|
|
215
|
+
|
|
216
|
+
unless override
|
|
217
|
+
count_apps = queued_count
|
|
218
|
+
if count_apps == 0
|
|
219
|
+
locked = acquire_lock
|
|
220
|
+
return unless locked
|
|
221
|
+
count_apps = queued_count
|
|
222
|
+
end
|
|
223
|
+
count_not = Resque.aps_notification_count_for_application(name)
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
if count_apps <= 0 || (count_apps < Resque.aps_application_job_limit && (count_not > Resque.aps_queue_size_upper && count_not % (Resque.aps_queue_size_upper / 10) == 0))
|
|
227
|
+
enqueue(Resque::Plugins::Aps::Application, name)
|
|
228
|
+
redis.incr(Resque.aps_application_queued_key(name))
|
|
229
|
+
delete_lock if locked
|
|
230
|
+
end
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
def dequeue
|
|
234
|
+
redis.decr(Resque.aps_application_queued_key(name))
|
|
235
|
+
end
|
|
236
|
+
|
|
180
237
|
end
|
|
181
238
|
end
|
|
182
239
|
end
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
<th>Notification Count</th>
|
|
15
15
|
<th></th>
|
|
16
16
|
</tr>
|
|
17
|
-
<% resque.aps_application_names(start,
|
|
17
|
+
<% resque.aps_application_names(start, 20).each do |application_name| %>
|
|
18
18
|
<tr>
|
|
19
19
|
<td><a href="<%= url "aps/#{application_name}" %>"><%= application_name %></a></td>
|
|
20
20
|
<td><%= resque.aps_notification_count_for_application(application_name) %></td>
|
data/test/resque-web_test.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: resque-aps
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
|
|
4
|
+
hash: 37
|
|
5
|
+
prerelease: false
|
|
6
|
+
segments:
|
|
7
|
+
- 0
|
|
8
|
+
- 9
|
|
9
|
+
- 15
|
|
10
|
+
version: 0.9.15
|
|
5
11
|
platform: ruby
|
|
6
12
|
authors:
|
|
7
13
|
- Ashley Martens
|
|
@@ -9,59 +15,51 @@ autorequire:
|
|
|
9
15
|
bindir: bin
|
|
10
16
|
cert_chain: []
|
|
11
17
|
|
|
12
|
-
date: 2010-
|
|
18
|
+
date: 2010-10-18 00:00:00 -07:00
|
|
13
19
|
default_executable:
|
|
14
20
|
dependencies:
|
|
15
|
-
- !ruby/object:Gem::Dependency
|
|
16
|
-
name: redis
|
|
17
|
-
type: :runtime
|
|
18
|
-
version_requirement:
|
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
20
|
-
requirements:
|
|
21
|
-
- - ">="
|
|
22
|
-
- !ruby/object:Gem::Version
|
|
23
|
-
version: 1.0.7
|
|
24
|
-
version:
|
|
25
|
-
- !ruby/object:Gem::Dependency
|
|
26
|
-
name: resque
|
|
27
|
-
type: :runtime
|
|
28
|
-
version_requirement:
|
|
29
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
30
|
-
requirements:
|
|
31
|
-
- - ">="
|
|
32
|
-
- !ruby/object:Gem::Version
|
|
33
|
-
version: 1.5.0
|
|
34
|
-
version:
|
|
35
21
|
- !ruby/object:Gem::Dependency
|
|
36
22
|
name: jeweler
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
23
|
+
prerelease: false
|
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
|
25
|
+
none: false
|
|
40
26
|
requirements:
|
|
41
27
|
- - ">="
|
|
42
28
|
- !ruby/object:Gem::Version
|
|
29
|
+
hash: 3
|
|
30
|
+
segments:
|
|
31
|
+
- 0
|
|
43
32
|
version: "0"
|
|
44
|
-
|
|
33
|
+
type: :development
|
|
34
|
+
version_requirements: *id001
|
|
45
35
|
- !ruby/object:Gem::Dependency
|
|
46
36
|
name: mocha
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
37
|
+
prerelease: false
|
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
|
39
|
+
none: false
|
|
50
40
|
requirements:
|
|
51
41
|
- - ">="
|
|
52
42
|
- !ruby/object:Gem::Version
|
|
43
|
+
hash: 3
|
|
44
|
+
segments:
|
|
45
|
+
- 0
|
|
53
46
|
version: "0"
|
|
54
|
-
|
|
47
|
+
type: :development
|
|
48
|
+
version_requirements: *id002
|
|
55
49
|
- !ruby/object:Gem::Dependency
|
|
56
50
|
name: rack-test
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
51
|
+
prerelease: false
|
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
|
53
|
+
none: false
|
|
60
54
|
requirements:
|
|
61
55
|
- - ">="
|
|
62
56
|
- !ruby/object:Gem::Version
|
|
57
|
+
hash: 3
|
|
58
|
+
segments:
|
|
59
|
+
- 0
|
|
63
60
|
version: "0"
|
|
64
|
-
|
|
61
|
+
type: :development
|
|
62
|
+
version_requirements: *id003
|
|
65
63
|
description: |-
|
|
66
64
|
Queuing system for Apple's Push Service on top of Resque.
|
|
67
65
|
Adds methods enqueue_aps to queue a notification message.
|
|
@@ -111,21 +109,27 @@ rdoc_options:
|
|
|
111
109
|
require_paths:
|
|
112
110
|
- lib
|
|
113
111
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
112
|
+
none: false
|
|
114
113
|
requirements:
|
|
115
114
|
- - ">="
|
|
116
115
|
- !ruby/object:Gem::Version
|
|
116
|
+
hash: 3
|
|
117
|
+
segments:
|
|
118
|
+
- 0
|
|
117
119
|
version: "0"
|
|
118
|
-
version:
|
|
119
120
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
121
|
+
none: false
|
|
120
122
|
requirements:
|
|
121
123
|
- - ">="
|
|
122
124
|
- !ruby/object:Gem::Version
|
|
125
|
+
hash: 3
|
|
126
|
+
segments:
|
|
127
|
+
- 0
|
|
123
128
|
version: "0"
|
|
124
|
-
version:
|
|
125
129
|
requirements: []
|
|
126
130
|
|
|
127
131
|
rubyforge_project:
|
|
128
|
-
rubygems_version: 1.3.
|
|
132
|
+
rubygems_version: 1.3.7
|
|
129
133
|
signing_key:
|
|
130
134
|
specification_version: 3
|
|
131
135
|
summary: Queuing system for Apple's Push Service on top of Resque
|