resque-aps 0.9.3 → 0.9.4

Sign up to get free protection for your applications and to get access to all the features.
data/HISTORY.md CHANGED
@@ -1,5 +1,12 @@
1
1
  ## 0.9.3 (2010-07-08)
2
2
 
3
+ * Use redis.[rpush,lpop,lrange] commands rather than Resque.[push,pop,peek] so that Resque queues are not created for the notifications.
4
+ * Add a rescue around create_sockets to transform the exception into an application exception before raising it.
5
+ * Fix the aps_application.erb table and link to the notifications.
6
+ * Fix the application test.
7
+
8
+ ## 0.9.3 (2010-07-08)
9
+
3
10
  * Remove the aps_application class attribute. It's Ruby monkey patch the Application class.
4
11
 
5
12
  ## 0.9.2 (2010-07-07)
@@ -94,11 +94,15 @@ module ResqueAps
94
94
  logger.debug("resque-aps: ssl_socket(#{name})") if logger
95
95
  exc = nil
96
96
 
97
- socket, ssl_socket = Application.create_sockets(cert || File.read(cert_file),
98
- certp || cert_passwd,
99
- host || Resque.aps_gateway_host,
100
- port || Resque.aps_gateway_port)
101
-
97
+ begin
98
+ socket, ssl_socket = Application.create_sockets(cert || File.read(cert_file),
99
+ certp || cert_passwd,
100
+ host || Resque.aps_gateway_host,
101
+ port || Resque.aps_gateway_port)
102
+ rescue
103
+ raise Application.application_exception($!, name)
104
+ end
105
+
102
106
  begin
103
107
  ssl_socket.connect
104
108
  yield ssl_socket, self if block_given?
@@ -10,13 +10,12 @@
10
10
 
11
11
  <table>
12
12
  <tr>
13
- <th></th>
14
13
  <th>Application</th>
15
- <th>Notification count</th>
14
+ <th>Notification Count</th>
16
15
  </tr>
17
16
  <% resque.aps_application_names(start, start+20).each do |application_name| %>
18
17
  <tr>
19
- <td><a href="<%= url "aps_applicatons/#{application_name}" %>"><%= application_name %></a></td>
18
+ <td><a href="<%= url "aps/#{application_name}" %>"><%= application_name %></a></td>
20
19
  <td><%= resque.aps_notification_count_for_application(application_name) %></td>
21
20
  </tr>
22
21
  <% end %>
@@ -1,3 +1,3 @@
1
1
  module ResqueAps
2
- Version = '0.9.3'
2
+ Version = '0.9.4'
3
3
  end
data/lib/resque_aps.rb CHANGED
@@ -7,6 +7,7 @@ require 'resque_aps/version'
7
7
  require 'resque_aps/server'
8
8
  require 'resque_aps/application'
9
9
  require 'resque_aps/notification'
10
+ require 'resque_aps/unknown_attribute_error'
10
11
 
11
12
  module ResqueAps
12
13
 
@@ -72,27 +73,27 @@ module ResqueAps
72
73
 
73
74
  def enqueue_aps(application_name, notification)
74
75
  count = aps_notification_count_for_application(application_name)
75
- push(aps_application_queue_key(application_name), notification.to_hash)
76
+ redis.rpush(aps_application_queue_key(application_name), encode(notification.to_hash))
76
77
  enqueue(ResqueAps::Application, application_name) if count <= aps_queue_size_lower || count >= aps_queue_size_upper
77
78
  true
78
79
  end
79
80
 
80
81
  def dequeue_aps(application_name)
81
- h = pop(aps_application_queue_key(application_name))
82
+ h = decode(redis.lpop(aps_application_queue_key(application_name)))
82
83
  return ResqueAps::Notification.new(h) if h
83
84
  nil
84
85
  end
85
86
 
86
87
  # Returns the number of queued notifications for a given application
87
88
  def aps_notification_count_for_application(application_name)
88
- size(aps_application_queue_key(application_name))
89
+ redis.llen(aps_application_queue_key(application_name)).to_i
89
90
  end
90
91
 
91
92
  # Returns an array of queued notifications for the given application
92
93
  def aps_notifications_for_application(application_name, start = 0, count = 1)
93
- r = peek(aps_application_queue_key(application_name), start, count)
94
+ r = redis.lrange(aps_application_queue_key(application_name), start, count)
94
95
  if r
95
- r.map { |h| ResqueAps::Notification.new(h) }
96
+ r.map { |h| ResqueAps::Notification.new(decode(h)) }
96
97
  else
97
98
  []
98
99
  end
@@ -26,33 +26,34 @@ context "ResqueAps::Application" do
26
26
  end
27
27
 
28
28
  context "ApplicationWithHooks" do
29
- class ApplicationWithHooks < ResqueAps::Application
30
- def before_aps_write(notification)
31
- logger.debug "before_aps_write #{notification.inspect}"
32
- end
33
-
34
- def after_aps_write(notification)
35
- logger.debug "after_aps_write #{notification.inspect}"
36
- end
37
-
38
- def failed_aps_write(notification, exception)
39
- logger.debug "failed_aps_write #{notification.inspect}"
40
- end
41
-
42
- def notify_aps_admin(exception)
43
- logger.debug "notify_aps_admin #{exception}"
44
- end
45
-
46
- def aps_nil_notification_retry?(sent_count, start_time)
47
- logger.debug "aps_nil_notification_retry #{sent_count}"
48
- false
29
+ module ResqueAps
30
+ class Application
31
+ def before_aps_write(notification)
32
+ logger.debug "before_aps_write #{notification.inspect}"
33
+ end
34
+
35
+ def after_aps_write(notification)
36
+ logger.debug "after_aps_write #{notification.inspect}"
37
+ end
38
+
39
+ def failed_aps_write(notification, exception)
40
+ logger.debug "failed_aps_write #{notification.inspect}"
41
+ end
42
+
43
+ def notify_aps_admin(exception)
44
+ logger.debug "notify_aps_admin #{exception}"
45
+ end
46
+
47
+ def aps_nil_notification_retry?(sent_count, start_time)
48
+ logger.debug "aps_nil_notification_retry #{sent_count}"
49
+ false
50
+ end
49
51
  end
50
52
  end
51
53
 
52
54
  test "can perform with logging hooks" do
53
55
  n = ResqueAps::Notification.new('application_name' => 'TestApp', 'device_token' => 'aihdf08u2402hbdfquhiwr', 'payload' => '{"aps": { "alert": "hello"}}')
54
56
  assert Resque.enqueue_aps('TestApp', n)
55
- Resque.aps_application_class = ApplicationWithHooks
56
57
  Resque.create_aps_application('TestApp', File.dirname(__FILE__) + "/../test-dev.pem", nil)
57
58
  ResqueAps::Application.perform('TestApp')
58
59
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 9
8
- - 3
9
- version: 0.9.3
8
+ - 4
9
+ version: 0.9.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Ashley Martens