Permalink
Browse files

emergency bug fix - had a runaway

  • Loading branch information...
1 parent 67951b3 commit 2283df835ce4148a5c5f8c0fc1406e399fc34f96 Greg Barnett committed Dec 18, 2011
Showing with 8 additions and 5 deletions.
  1. +8 −5 app/models/apn/app.rb
View
13 app/models/apn/app.rb
@@ -62,15 +62,18 @@ def self.send_notifications
# As each notification is sent the <tt>sent_at</tt> column will be timestamped,
# so as to not be sent again.
#
- def send_notifications(recursions = 0)
- # return if self.unsent_notifications.nil? || self.unsent_notifications.empty?
- raise ArgumentError, 'infinite recursion' if recursions > self.notifications.count
+ def send_notifications(recursions = 0, max_attempts = nil)
+ # TEMP - setting max_attempts to 3, just in case this code is wrong
+ max_attempts = 3
+
+ max_attempts ||= unsent_notifications(true).count
+ raise ArgumentError, 'too many recursions' if recursions > max_attempts
failed_notification_id = nil
checked_for_apns_errors = false
sent_noty_ids = []
APN::Connection.open_for_delivery({:cert => cert, :host => gateway_server}) do |conn, sock|
- unsent_notifications.each do |noty|
+ unsent_notifications(true).find_each do |noty|
# We start out being optimistic that this noty will be sent.
# This also helps us to backtrack when we get an error and have to resend notys after the one that failed.
noty.update_attribute(:sent_at, Time.now)
@@ -92,7 +95,7 @@ def send_notifications(recursions = 0)
unless failed_notification_id.nil?
unsend_notifications_sent_after_failure(failed_notification_id, sent_noty_ids)
- send_notifications(recursions + 1)
+ send_notifications(recursions + 1, max_attempts)
end
end
end

0 comments on commit 2283df8

Please sign in to comment.