Class: Rapns::Daemon::Batch
- Inherits:
-
Object
- Object
- Rapns::Daemon::Batch
- Includes:
- Reflectable
- Defined in:
- lib/rapns/daemon/batch.rb
Instance Attribute Summary collapse
-
#delivered ⇒ Object
readonly
Returns the value of attribute delivered.
-
#failed ⇒ Object
readonly
Returns the value of attribute failed.
-
#notifications ⇒ Object
readonly
Returns the value of attribute notifications.
-
#num_processed ⇒ Object
readonly
Returns the value of attribute num_processed.
-
#retryable ⇒ Object
readonly
Returns the value of attribute retryable.
Instance Method Summary collapse
- #complete? ⇒ Boolean
- #describe ⇒ Object
-
#initialize(notifications) ⇒ Batch
constructor
A new instance of Batch.
- #mark_delivered(notification) ⇒ Object
- #mark_failed(notification, code, description) ⇒ Object
- #mark_retryable(notification, deliver_after) ⇒ Object
- #notification_processed ⇒ Object
- #num_notifications ⇒ Object
Methods included from Reflectable
Constructor Details
#initialize(notifications) ⇒ Batch
Returns a new instance of Batch.
9 10 11 12 13 14 15 16 |
# File 'lib/rapns/daemon/batch.rb', line 9 def initialize(notifications) @notifications = notifications @num_processed = 0 @delivered = [] @failed = {} @retryable = {} @mutex = Mutex.new end |
Instance Attribute Details
#delivered ⇒ Object (readonly)
Returns the value of attribute delivered.
6 7 8 |
# File 'lib/rapns/daemon/batch.rb', line 6 def delivered @delivered end |
#failed ⇒ Object (readonly)
Returns the value of attribute failed.
6 7 8 |
# File 'lib/rapns/daemon/batch.rb', line 6 def failed @failed end |
#notifications ⇒ Object (readonly)
Returns the value of attribute notifications.
6 7 8 |
# File 'lib/rapns/daemon/batch.rb', line 6 def notifications @notifications end |
#num_processed ⇒ Object (readonly)
Returns the value of attribute num_processed.
6 7 8 |
# File 'lib/rapns/daemon/batch.rb', line 6 def num_processed @num_processed end |
#retryable ⇒ Object (readonly)
Returns the value of attribute retryable.
6 7 8 |
# File 'lib/rapns/daemon/batch.rb', line 6 def retryable @retryable end |
Instance Method Details
#complete? ⇒ Boolean
56 57 58 |
# File 'lib/rapns/daemon/batch.rb', line 56 def complete? @complete == true end |
#describe ⇒ Object
60 61 62 |
# File 'lib/rapns/daemon/batch.rb', line 60 def describe @notifications.map(&:id).join(', ') end |
#mark_delivered(notification) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/rapns/daemon/batch.rb', line 31 def mark_delivered(notification) if Rapns.config.batch_storage_updates @delivered << notification else Rapns::Daemon.store.mark_delivered(notification) end end |
#mark_failed(notification, code, description) ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/rapns/daemon/batch.rb', line 39 def mark_failed(notification, code, description) if Rapns.config.batch_storage_updates key = [code, description] @failed[key] ||= [] @failed[key] << notification else Rapns::Daemon.store.mark_failed(notification, code, description) end end |
#mark_retryable(notification, deliver_after) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/rapns/daemon/batch.rb', line 22 def mark_retryable(notification, deliver_after) if Rapns.config.batch_storage_updates @retryable[deliver_after] ||= [] @retryable[deliver_after] << notification else Rapns::Daemon.store.mark_retryable(notification, deliver_after) end end |
#notification_processed ⇒ Object
49 50 51 52 53 54 |
# File 'lib/rapns/daemon/batch.rb', line 49 def notification_processed @mutex.synchronize do @num_processed += 1 complete if @num_processed >= @notifications.size end end |
#num_notifications ⇒ Object
18 19 20 |
# File 'lib/rapns/daemon/batch.rb', line 18 def num_notifications @notifications.size end |