class Rpush::Daemon::Batch
Attributes
delivered[R]
failed[R]
notifications[R]
num_processed[R]
retryable[R]
Public Class Methods
new(notifications)
click to toggle source
# File lib/rpush/daemon/batch.rb, line 8 def initialize(notifications) @notifications = notifications @num_processed = 0 @delivered = [] @failed = {} @retryable = {} @mutex = Mutex.new end
Public Instance Methods
all_processed()
click to toggle source
# File lib/rpush/daemon/batch.rb, line 88 def all_processed @mutex.synchronize do @num_processed = @notifications.size complete end end
complete?()
click to toggle source
# File lib/rpush/daemon/batch.rb, line 17 def complete? @complete == true end
each_delivered(&blk)
click to toggle source
# File lib/rpush/daemon/batch.rb, line 25 def each_delivered(&blk) @delivered.each(&blk) end
each_notification(&blk)
click to toggle source
# File lib/rpush/daemon/batch.rb, line 21 def each_notification(&blk) @notifications.each(&blk) end
mark_all_delivered()
click to toggle source
# File lib/rpush/daemon/batch.rb, line 53 def mark_all_delivered @mutex.synchronize do @delivered = @notifications end each_notification do |notification| Rpush::Daemon.store.mark_delivered(notification, Time.now, persist: false) end end
mark_all_failed(code, message)
click to toggle source
# File lib/rpush/daemon/batch.rb, line 71 def mark_all_failed(code, message) key = [code, message] @mutex.synchronize do @failed[key] = @notifications end each_notification do |notification| Rpush::Daemon.store.mark_failed(notification, code, message, Time.now, persist: false) end end
mark_all_retryable(deliver_after)
click to toggle source
# File lib/rpush/daemon/batch.rb, line 37 def mark_all_retryable(deliver_after) @mutex.synchronize do @retryable[deliver_after] = @notifications end each_notification do |notification| Rpush::Daemon.store.mark_retryable(notification, deliver_after, persist: false) end end
mark_delivered(notification)
click to toggle source
# File lib/rpush/daemon/batch.rb, line 46 def mark_delivered(notification) @mutex.synchronize do @delivered << notification end Rpush::Daemon.store.mark_delivered(notification, Time.now, persist: false) end
mark_failed(notification, code, description)
click to toggle source
# File lib/rpush/daemon/batch.rb, line 62 def mark_failed(notification, code, description) key = [code, description] @mutex.synchronize do @failed[key] ||= [] @failed[key] << notification end Rpush::Daemon.store.mark_failed(notification, code, description, Time.now, persist: false) end
mark_retryable(notification, deliver_after)
click to toggle source
# File lib/rpush/daemon/batch.rb, line 29 def mark_retryable(notification, deliver_after) @mutex.synchronize do @retryable[deliver_after] ||= [] @retryable[deliver_after] << notification end Rpush::Daemon.store.mark_retryable(notification, deliver_after, persist: false) end
notification_processed()
click to toggle source
# File lib/rpush/daemon/batch.rb, line 81 def notification_processed @mutex.synchronize do @num_processed += 1 complete if @num_processed >= @notifications.size end end
Private Instance Methods
complete()
click to toggle source
# File lib/rpush/daemon/batch.rb, line 97 def complete return if complete? [:complete_delivered, :complete_failed, :complete_retried].each do |method| begin send(method) rescue StandardError => e Rpush.logger.error(e) reflect(:error, e) end end @complete = true end
complete_delivered()
click to toggle source
# File lib/rpush/daemon/batch.rb, line 112 def complete_delivered Rpush::Daemon.store.mark_batch_delivered(@delivered) @delivered.each do |notification| reflect(:notification_delivered, notification) end end
complete_failed()
click to toggle source
# File lib/rpush/daemon/batch.rb, line 119 def complete_failed @failed.each do |(code, description), notifications| Rpush::Daemon.store.mark_batch_failed(notifications, code, description) notifications.each do |notification| reflect(:notification_failed, notification) end end end
complete_retried()
click to toggle source
# File lib/rpush/daemon/batch.rb, line 128 def complete_retried @retryable.each do |deliver_after, notifications| Rpush::Daemon.store.mark_batch_retryable(notifications, deliver_after) notifications.each do |notification| reflect(:notification_will_retry, notification) end end end