resque-aps 0.9.13 → 0.9.14
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 +4 -0
- data/lib/{resque_aps → resque/plugins/aps}/application.rb +0 -0
- data/lib/{resque_aps → resque/plugins/aps}/feedback.rb +0 -0
- data/lib/{resque_aps → resque/plugins/aps}/helper.rb +0 -0
- data/lib/{resque_aps → resque/plugins/aps}/notification.rb +0 -0
- data/lib/{resque_aps → resque/plugins/aps}/server/test_helper.rb +0 -0
- data/lib/{resque_aps → resque/plugins/aps}/server/views/aps_applications.erb +0 -0
- data/lib/{resque_aps → resque/plugins/aps}/server/views/notifications.erb +0 -0
- data/lib/{resque_aps → resque/plugins/aps}/server.rb +0 -0
- data/lib/{resque_aps → resque/plugins/aps}/tasks.rb +0 -0
- data/lib/{resque_aps → resque/plugins/aps}/unknown_attribute_error.rb +0 -0
- data/lib/{resque_aps → resque/plugins/aps}/version.rb +1 -1
- data/lib/resque/plugins/aps.rb +147 -0
- data/lib/resque_aps.rb +8 -155
- data/tasks/resque_aps.rake +1 -1
- metadata +13 -12
data/HISTORY.md
CHANGED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,147 @@
|
|
1
|
+
module Resque
|
2
|
+
module Plugins
|
3
|
+
module Aps
|
4
|
+
|
5
|
+
def logger=(logger)
|
6
|
+
@logger = logger
|
7
|
+
end
|
8
|
+
|
9
|
+
def logger
|
10
|
+
unless @logger
|
11
|
+
@logger = Logger.new(STDOUT)
|
12
|
+
@logger.level = Logger::WARN
|
13
|
+
end
|
14
|
+
@logger
|
15
|
+
end
|
16
|
+
|
17
|
+
def aps_gateway_host=(host)
|
18
|
+
@aps_gateway_host = host
|
19
|
+
end
|
20
|
+
|
21
|
+
def aps_gateway_host
|
22
|
+
@aps_gateway_host ||= "gateway.sandbox.push.apple.com"
|
23
|
+
end
|
24
|
+
|
25
|
+
def aps_gateway_port=(port)
|
26
|
+
@aps_gateway_port = port
|
27
|
+
end
|
28
|
+
|
29
|
+
def aps_gateway_port
|
30
|
+
@aps_gateway_port ||= 2195
|
31
|
+
end
|
32
|
+
|
33
|
+
def aps_feedback_host=(host)
|
34
|
+
@aps_feedback_host = host
|
35
|
+
end
|
36
|
+
|
37
|
+
def aps_feedback_host
|
38
|
+
@aps_feedback_host ||= "feedback.sandbox.push.apple.com"
|
39
|
+
end
|
40
|
+
|
41
|
+
def aps_feedback_port=(port)
|
42
|
+
@aps_feedback_port = port
|
43
|
+
end
|
44
|
+
|
45
|
+
def aps_feedback_port
|
46
|
+
@aps_feedback_port ||= 2196
|
47
|
+
end
|
48
|
+
|
49
|
+
def aps_queue_size_upper=(size)
|
50
|
+
@aps_queue_size_upper = size
|
51
|
+
end
|
52
|
+
|
53
|
+
def aps_queue_size_upper
|
54
|
+
@aps_queue_size_upper ||= 1000
|
55
|
+
end
|
56
|
+
|
57
|
+
def aps_application_job_limit=(size)
|
58
|
+
@aps_queue_size_upper = size
|
59
|
+
end
|
60
|
+
|
61
|
+
def aps_application_job_limit
|
62
|
+
@aps_application_job_limit ||= 5
|
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
|
+
|
82
|
+
def enqueue_aps(application_name, notification)
|
83
|
+
redis.rpush(aps_application_queue_key(application_name), encode(notification.to_hash))
|
84
|
+
enqueue_aps_application(application_name)
|
85
|
+
true
|
86
|
+
end
|
87
|
+
|
88
|
+
def dequeue_aps(application_name)
|
89
|
+
h = decode(redis.lpop(aps_application_queue_key(application_name)))
|
90
|
+
return Resque::Plugins::Aps::Notification.new(h) if h
|
91
|
+
nil
|
92
|
+
end
|
93
|
+
|
94
|
+
# Returns the number of queued notifications for a given application
|
95
|
+
def aps_notification_count_for_application(application_name)
|
96
|
+
redis.llen(aps_application_queue_key(application_name)).to_i
|
97
|
+
end
|
98
|
+
|
99
|
+
# Returns an array of queued notifications for the given application
|
100
|
+
def aps_notifications_for_application(application_name, start = 0, count = 1)
|
101
|
+
r = redis.lrange(aps_application_queue_key(application_name), start, count)
|
102
|
+
if r
|
103
|
+
r.map { |h| Resque::Plugins::Aps::Notification.new(decode(h)) }
|
104
|
+
else
|
105
|
+
[]
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def create_aps_application(name, cert_file, cert_passwd = nil)
|
110
|
+
redis.set(aps_application_key(name), encode({'name' => name, 'cert_file' => cert_file, 'cert_passwd' => cert_passwd}))
|
111
|
+
redis.sadd(:aps_applications, name)
|
112
|
+
end
|
113
|
+
|
114
|
+
def aps_application(name)
|
115
|
+
h = decode(redis.get(aps_application_key(name)))
|
116
|
+
return Resque::Plugins::Aps::Application.new(h) if h
|
117
|
+
nil
|
118
|
+
end
|
119
|
+
|
120
|
+
# Returns an array of applications based on start and count
|
121
|
+
def aps_application_names(start = 0, count = 1)
|
122
|
+
a = redis.smembers(:aps_applications)
|
123
|
+
return a if count == 0
|
124
|
+
ret = a[start..(start + count)]
|
125
|
+
return [] unless ret
|
126
|
+
ret
|
127
|
+
end
|
128
|
+
|
129
|
+
# Returns the number of application queues
|
130
|
+
def aps_applications_count
|
131
|
+
redis.smembers(:aps_applications).size
|
132
|
+
end
|
133
|
+
|
134
|
+
def aps_application_key(application_name)
|
135
|
+
"aps:application:#{application_name}"
|
136
|
+
end
|
137
|
+
|
138
|
+
def aps_application_queued_key(application_name)
|
139
|
+
"#{aps_application_key(application_name)}:queued"
|
140
|
+
end
|
141
|
+
|
142
|
+
def aps_application_queue_key(application_name)
|
143
|
+
"#{aps_application_key(application_name)}:queue"
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
data/lib/resque_aps.rb
CHANGED
@@ -2,161 +2,14 @@ require 'rubygems'
|
|
2
2
|
require 'resque'
|
3
3
|
require 'logger'
|
4
4
|
require 'resque/server'
|
5
|
-
require '
|
6
|
-
require '
|
7
|
-
require '
|
8
|
-
require '
|
9
|
-
require '
|
10
|
-
require '
|
11
|
-
require '
|
12
|
-
|
13
|
-
module Resque
|
14
|
-
module Plugins
|
15
|
-
module Aps
|
16
|
-
|
17
|
-
def logger=(logger)
|
18
|
-
@logger = logger
|
19
|
-
end
|
20
|
-
|
21
|
-
def logger
|
22
|
-
unless @logger
|
23
|
-
@logger = Logger.new(STDOUT)
|
24
|
-
@logger.level = Logger::WARN
|
25
|
-
end
|
26
|
-
@logger
|
27
|
-
end
|
28
|
-
|
29
|
-
def aps_gateway_host=(host)
|
30
|
-
@aps_gateway_host = host
|
31
|
-
end
|
32
|
-
|
33
|
-
def aps_gateway_host
|
34
|
-
@aps_gateway_host ||= "gateway.sandbox.push.apple.com"
|
35
|
-
end
|
36
|
-
|
37
|
-
def aps_gateway_port=(port)
|
38
|
-
@aps_gateway_port = port
|
39
|
-
end
|
40
|
-
|
41
|
-
def aps_gateway_port
|
42
|
-
@aps_gateway_port ||= 2195
|
43
|
-
end
|
44
|
-
|
45
|
-
def aps_feedback_host=(host)
|
46
|
-
@aps_feedback_host = host
|
47
|
-
end
|
48
|
-
|
49
|
-
def aps_feedback_host
|
50
|
-
@aps_feedback_host ||= "feedback.sandbox.push.apple.com"
|
51
|
-
end
|
52
|
-
|
53
|
-
def aps_feedback_port=(port)
|
54
|
-
@aps_feedback_port = port
|
55
|
-
end
|
56
|
-
|
57
|
-
def aps_feedback_port
|
58
|
-
@aps_feedback_port ||= 2196
|
59
|
-
end
|
60
|
-
|
61
|
-
def aps_queue_size_upper=(size)
|
62
|
-
@aps_queue_size_upper = size
|
63
|
-
end
|
64
|
-
|
65
|
-
def aps_queue_size_upper
|
66
|
-
@aps_queue_size_upper ||= 1000
|
67
|
-
end
|
68
|
-
|
69
|
-
def aps_application_job_limit=(size)
|
70
|
-
@aps_queue_size_upper = size
|
71
|
-
end
|
72
|
-
|
73
|
-
def aps_application_job_limit
|
74
|
-
@aps_application_job_limit ||= 5
|
75
|
-
end
|
76
|
-
|
77
|
-
def aps_applications_queued_count(application_name)
|
78
|
-
redis.get(aps_application_queued_key(application_name)) || 0
|
79
|
-
end
|
80
|
-
|
81
|
-
def enqueue_aps_application(application_name, override = false)
|
82
|
-
count_apps = aps_applications_queued_count(application_name).to_i
|
83
|
-
count_not = aps_notification_count_for_application(application_name)
|
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
|
-
enqueue(Resque::Plugins::Aps::Application, application_name)
|
86
|
-
redis.incr(aps_application_queued_key(application_name))
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
def dequeue_aps_application(application_name)
|
91
|
-
redis.decr(aps_application_queued_key(application_name)) if aps_applications_queued_count(application_name).to_i > 0
|
92
|
-
end
|
93
|
-
|
94
|
-
def enqueue_aps(application_name, notification)
|
95
|
-
redis.rpush(aps_application_queue_key(application_name), encode(notification.to_hash))
|
96
|
-
enqueue_aps_application(application_name)
|
97
|
-
true
|
98
|
-
end
|
99
|
-
|
100
|
-
def dequeue_aps(application_name)
|
101
|
-
h = decode(redis.lpop(aps_application_queue_key(application_name)))
|
102
|
-
return Resque::Plugins::Aps::Notification.new(h) if h
|
103
|
-
nil
|
104
|
-
end
|
105
|
-
|
106
|
-
# Returns the number of queued notifications for a given application
|
107
|
-
def aps_notification_count_for_application(application_name)
|
108
|
-
redis.llen(aps_application_queue_key(application_name)).to_i
|
109
|
-
end
|
110
|
-
|
111
|
-
# Returns an array of queued notifications for the given application
|
112
|
-
def aps_notifications_for_application(application_name, start = 0, count = 1)
|
113
|
-
r = redis.lrange(aps_application_queue_key(application_name), start, count)
|
114
|
-
if r
|
115
|
-
r.map { |h| Resque::Plugins::Aps::Notification.new(decode(h)) }
|
116
|
-
else
|
117
|
-
[]
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
def create_aps_application(name, cert_file, cert_passwd = nil)
|
122
|
-
redis.set(aps_application_key(name), encode({'name' => name, 'cert_file' => cert_file, 'cert_passwd' => cert_passwd}))
|
123
|
-
redis.sadd(:aps_applications, name)
|
124
|
-
end
|
125
|
-
|
126
|
-
def aps_application(name)
|
127
|
-
h = decode(redis.get(aps_application_key(name)))
|
128
|
-
return Resque::Plugins::Aps::Application.new(h) if h
|
129
|
-
nil
|
130
|
-
end
|
131
|
-
|
132
|
-
# Returns an array of applications based on start and count
|
133
|
-
def aps_application_names(start = 0, count = 1)
|
134
|
-
a = redis.smembers(:aps_applications)
|
135
|
-
return a if count == 0
|
136
|
-
ret = a[start..(start + count)]
|
137
|
-
return [] unless ret
|
138
|
-
ret
|
139
|
-
end
|
140
|
-
|
141
|
-
# Returns the number of application queues
|
142
|
-
def aps_applications_count
|
143
|
-
redis.smembers(:aps_applications).size
|
144
|
-
end
|
145
|
-
|
146
|
-
def aps_application_key(application_name)
|
147
|
-
"aps:application:#{application_name}"
|
148
|
-
end
|
149
|
-
|
150
|
-
def aps_application_queued_key(application_name)
|
151
|
-
"#{aps_application_key(application_name)}:queued"
|
152
|
-
end
|
153
|
-
|
154
|
-
def aps_application_queue_key(application_name)
|
155
|
-
"#{aps_application_key(application_name)}:queue"
|
156
|
-
end
|
157
|
-
end
|
158
|
-
end
|
159
|
-
end
|
5
|
+
require 'resque/plugins/aps'
|
6
|
+
require 'resque/plugins/aps/helper'
|
7
|
+
require 'resque/plugins/aps/version'
|
8
|
+
require 'resque/plugins/aps/server'
|
9
|
+
require 'resque/plugins/aps/application'
|
10
|
+
require 'resque/plugins/aps/notification'
|
11
|
+
require 'resque/plugins/aps/feedback'
|
12
|
+
require 'resque/plugins/aps/unknown_attribute_error'
|
160
13
|
|
161
14
|
Resque.extend Resque::Plugins::Aps
|
162
15
|
Resque::Server.class_eval do
|
data/tasks/resque_aps.rake
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
|
2
|
-
require '
|
2
|
+
require 'resque/plugins/aps/tasks'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: resque-aps
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ashley Martens
|
@@ -80,18 +80,19 @@ files:
|
|
80
80
|
- LICENSE
|
81
81
|
- README.markdown
|
82
82
|
- Rakefile
|
83
|
+
- lib/resque/plugins/aps.rb
|
84
|
+
- lib/resque/plugins/aps/application.rb
|
85
|
+
- lib/resque/plugins/aps/feedback.rb
|
86
|
+
- lib/resque/plugins/aps/helper.rb
|
87
|
+
- lib/resque/plugins/aps/notification.rb
|
88
|
+
- lib/resque/plugins/aps/server.rb
|
89
|
+
- lib/resque/plugins/aps/server/test_helper.rb
|
90
|
+
- lib/resque/plugins/aps/server/views/aps_applications.erb
|
91
|
+
- lib/resque/plugins/aps/server/views/notifications.erb
|
92
|
+
- lib/resque/plugins/aps/tasks.rb
|
93
|
+
- lib/resque/plugins/aps/unknown_attribute_error.rb
|
94
|
+
- lib/resque/plugins/aps/version.rb
|
83
95
|
- lib/resque_aps.rb
|
84
|
-
- lib/resque_aps/application.rb
|
85
|
-
- lib/resque_aps/feedback.rb
|
86
|
-
- lib/resque_aps/helper.rb
|
87
|
-
- lib/resque_aps/notification.rb
|
88
|
-
- lib/resque_aps/server.rb
|
89
|
-
- lib/resque_aps/server/test_helper.rb
|
90
|
-
- lib/resque_aps/server/views/aps_applications.erb
|
91
|
-
- lib/resque_aps/server/views/notifications.erb
|
92
|
-
- lib/resque_aps/tasks.rb
|
93
|
-
- lib/resque_aps/unknown_attribute_error.rb
|
94
|
-
- lib/resque_aps/version.rb
|
95
96
|
- tasks/resque_aps.rake
|
96
97
|
- test/application_test.rb
|
97
98
|
- test/feedback_test.rb
|