Module: Resque::Plugins::Aps
- Included in:
- Resque
- Defined in:
- lib/resque/plugins/aps/aps.rb,
lib/resque/plugins/aps/daemon.rb,
lib/resque/plugins/aps/helper.rb,
lib/resque/plugins/aps/server.rb,
lib/resque/plugins/aps/version.rb,
lib/resque/plugins/aps/feedback.rb,
lib/resque/plugins/aps/application.rb,
lib/resque/plugins/aps/notification.rb,
lib/resque/plugins/aps/server/test_helper.rb,
lib/resque/plugins/aps/unknown_attribute_error.rb
Defined Under Namespace
Modules: Helper, Server, TestHelper
Classes: Application, Daemon, Feedback, Notification, UnknownAttributeError
Constant Summary
collapse
- Version =
'0.9.17'
Instance Method Summary
collapse
Instance Method Details
#aps_age(application_name) ⇒ Object
Age of the oldest notification in the given application queue, in seconds returns 0 - if there are no notifications on the queue or the oldest has no create time
100
101
102
103
104
|
# File 'lib/resque/plugins/aps/aps.rb', line 100
def aps_age(application_name)
h = decode(redis.lindex(aps_application_queue_key(application_name), 0))
res = h ? h['created_at'] ? Time.now.utc - Time.parse(h['created_at']) : 0 : 0
return res
end
|
#aps_application(name) ⇒ Object
132
133
134
135
|
# File 'lib/resque/plugins/aps/aps.rb', line 132
def aps_application(name)
h = decode(redis.get(aps_application_key(name)))
h ? Resque::Plugins::Aps::Application.new(h) : nil
end
|
#aps_application_exists?(name) ⇒ Boolean
128
129
130
|
# File 'lib/resque/plugins/aps/aps.rb', line 128
def aps_application_exists?(name)
redis.exists(aps_application_key(name)) == 1
end
|
#aps_application_job_limit ⇒ Object
61
62
63
|
# File 'lib/resque/plugins/aps/aps.rb', line 61
def aps_application_job_limit
@aps_application_job_limit ||= 5
end
|
#aps_application_job_limit=(size) ⇒ Object
57
58
59
|
# File 'lib/resque/plugins/aps/aps.rb', line 57
def aps_application_job_limit=(size)
@aps_queue_size_upper = size
end
|
#aps_application_key(application_name) ⇒ Object
149
150
151
|
# File 'lib/resque/plugins/aps/aps.rb', line 149
def aps_application_key(application_name)
"aps:application:#{application_name}"
end
|
#aps_application_names(start = 0, count = 1) ⇒ Object
Returns an array of applications based on start and count
138
139
140
141
142
|
# File 'lib/resque/plugins/aps/aps.rb', line 138
def aps_application_names(start = 0, count = 1)
a = redis.smembers(:aps_applications)
return a if count == 0
a[start..(start + count)] || []
end
|
#aps_application_queue_key(application_name) ⇒ Object
157
158
159
|
# File 'lib/resque/plugins/aps/aps.rb', line 157
def aps_application_queue_key(application_name)
"#{aps_application_key(application_name)}:queue"
end
|
#aps_application_queued_key(application_name) ⇒ Object
153
154
155
|
# File 'lib/resque/plugins/aps/aps.rb', line 153
def aps_application_queued_key(application_name)
"#{aps_application_key(application_name)}:queued"
end
|
#aps_applications_count ⇒ Object
Returns the number of application queues
145
146
147
|
# File 'lib/resque/plugins/aps/aps.rb', line 145
def aps_applications_count
redis.smembers(:aps_applications).size
end
|
#aps_applications_queued_count(application_name) ⇒ Object
65
66
67
|
# File 'lib/resque/plugins/aps/aps.rb', line 65
def aps_applications_queued_count(application_name)
(redis.get(Resque.aps_application_queued_key(name)) || 0).to_i
end
|
#aps_feedback_host ⇒ Object
37
38
39
|
# File 'lib/resque/plugins/aps/aps.rb', line 37
def aps_feedback_host
@aps_feedback_host ||= "feedback.sandbox.push.apple.com"
end
|
#aps_feedback_host=(host) ⇒ Object
33
34
35
|
# File 'lib/resque/plugins/aps/aps.rb', line 33
def aps_feedback_host=(host)
@aps_feedback_host = host
end
|
#aps_feedback_port ⇒ Object
45
46
47
|
# File 'lib/resque/plugins/aps/aps.rb', line 45
def aps_feedback_port
@aps_feedback_port ||= 2196
end
|
#aps_feedback_port=(port) ⇒ Object
41
42
43
|
# File 'lib/resque/plugins/aps/aps.rb', line 41
def aps_feedback_port=(port)
@aps_feedback_port = port
end
|
#aps_gateway_host ⇒ Object
21
22
23
|
# File 'lib/resque/plugins/aps/aps.rb', line 21
def aps_gateway_host
@aps_gateway_host ||= "gateway.sandbox.push.apple.com"
end
|
#aps_gateway_host=(host) ⇒ Object
17
18
19
|
# File 'lib/resque/plugins/aps/aps.rb', line 17
def aps_gateway_host=(host)
@aps_gateway_host = host
end
|
#aps_gateway_port ⇒ Object
29
30
31
|
# File 'lib/resque/plugins/aps/aps.rb', line 29
def aps_gateway_port
@aps_gateway_port ||= 2195
end
|
#aps_gateway_port=(port) ⇒ Object
25
26
27
|
# File 'lib/resque/plugins/aps/aps.rb', line 25
def aps_gateway_port=(port)
@aps_gateway_port = port
end
|
#aps_notification_count_for_application(application_name) ⇒ Object
Returns the number of queued notifications for a given application
107
108
109
|
# File 'lib/resque/plugins/aps/aps.rb', line 107
def aps_notification_count_for_application(application_name)
redis.llen(aps_application_queue_key(application_name)).to_i
end
|
#aps_notifications_for_application(application_name, start = 0, count = 1) ⇒ Object
Returns an array of queued notifications for the given application
112
113
114
115
|
# File 'lib/resque/plugins/aps/aps.rb', line 112
def aps_notifications_for_application(application_name, start = 0, count = 1)
r = redis.lrange(aps_application_queue_key(application_name), start, count)
r ? r.map { |h| Resque::Plugins::Aps::Notification.new(decode(h)) } : []
end
|
#aps_queue_size_upper ⇒ Object
53
54
55
|
# File 'lib/resque/plugins/aps/aps.rb', line 53
def aps_queue_size_upper
@aps_queue_size_upper ||= 1000
end
|
#aps_queue_size_upper=(size) ⇒ Object
49
50
51
|
# File 'lib/resque/plugins/aps/aps.rb', line 49
def aps_queue_size_upper=(size)
@aps_queue_size_upper = size
end
|
#create_aps_application(name, cert_file, cert_passwd = nil) ⇒ Object
117
118
119
120
|
# File 'lib/resque/plugins/aps/aps.rb', line 117
def create_aps_application(name, cert_file, cert_passwd = nil)
redis.set(aps_application_key(name), encode({'name' => name, 'cert_file' => cert_file, 'cert_passwd' => cert_passwd}))
redis.sadd(:aps_applications, name)
end
|
#delete_aps_application(name) ⇒ Object
122
123
124
125
126
|
# File 'lib/resque/plugins/aps/aps.rb', line 122
def delete_aps_application(name)
redis.del(aps_application_key(name))
redis.srem(:aps_applications, name)
redis.del(aps_application_queue_key(name))
end
|
#dequeue_aps(application_name) ⇒ Object
Pop the oldest notification off the given application queue returns nil - if there are none on the queue
92
93
94
95
|
# File 'lib/resque/plugins/aps/aps.rb', line 92
def dequeue_aps(application_name)
h = decode(redis.lpop(aps_application_queue_key(application_name)))
h ? Resque::Plugins::Aps::Notification.new(h) : nil
end
|
#dequeue_aps_application(application_name) ⇒ Object
Decrease the count of queued application workers
75
76
77
|
# File 'lib/resque/plugins/aps/aps.rb', line 75
def dequeue_aps_application(application_name)
res = redis.decr(aps_application_queued_key(application_name))
end
|
#enqueue_aps(application_name, notification) ⇒ Object
Push the given notification onto the given application queue returns true
81
82
83
84
85
86
87
88
|
# File 'lib/resque/plugins/aps/aps.rb', line 81
def enqueue_aps(application_name, notification)
create_aps_application(application_name, nil, nil) unless aps_application_exists?(application_name)
redis.rpush(aps_application_queue_key(application_name), encode(notification.to_hash))
if inline?
Resque::Plugins::Aps::Application.perform(application_name, false)
end
true
end
|
#enqueue_aps_application(application_name, override = false) ⇒ Object
Increase the count of queued application workers
70
71
72
|
# File 'lib/resque/plugins/aps/aps.rb', line 70
def enqueue_aps_application(application_name, override = false)
res = redis.incr(aps_application_queued_key(application_name))
end
|
#logger ⇒ Object
9
10
11
12
13
14
15
|
# File 'lib/resque/plugins/aps/aps.rb', line 9
def logger
unless @logger
@logger = Logger.new(STDOUT)
@logger.level = Logger::WARN
end
@logger
end
|
#logger=(logger) ⇒ Object
5
6
7
|
# File 'lib/resque/plugins/aps/aps.rb', line 5
def logger=(logger)
@logger = logger
end
|