Class: Rpush::Daemon::Batch
- Inherits:
-
Object
- Object
- Rpush::Daemon::Batch
- Includes:
- Reflectable
- Defined in:
- lib/rpush/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_dispatched ⇒ 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/rpush/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/rpush/daemon/batch.rb', line 6 def delivered @delivered end |
#failed ⇒ Object (readonly)
Returns the value of attribute failed.
6 7 8 |
# File 'lib/rpush/daemon/batch.rb', line 6 def failed @failed end |
#notifications ⇒ Object (readonly)
Returns the value of attribute notifications.
6 7 8 |
# File 'lib/rpush/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/rpush/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/rpush/daemon/batch.rb', line 6 def retryable @retryable end |
Instance Method Details
#complete? ⇒ Boolean
62 63 64 |
# File 'lib/rpush/daemon/batch.rb', line 62 def complete? @complete == true end |
#describe ⇒ Object
66 67 68 |
# File 'lib/rpush/daemon/batch.rb', line 66 def describe notifications.map(&:id).join(', ') end |
#mark_delivered(notification) ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/rpush/daemon/batch.rb', line 33 def mark_delivered(notification) if Rpush.config.batch_storage_updates delivered << notification Rpush::Daemon.store.mark_delivered(notification, Time.now, :persist => false) else Rpush::Daemon.store.mark_delivered(notification, Time.now) reflect(:notification_delivered, notification) end end |
#mark_failed(notification, code, description) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/rpush/daemon/batch.rb', line 43 def mark_failed(notification, code, description) if Rpush.config.batch_storage_updates key = [code, description] failed[key] ||= [] failed[key] << notification Rpush::Daemon.store.mark_failed(notification, code, description, Time.now, :persist => false) else Rpush::Daemon.store.mark_failed(notification, code, description, Time.now) reflect(:notification_failed, notification) end end |
#mark_retryable(notification, deliver_after) ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/rpush/daemon/batch.rb', line 22 def mark_retryable(notification, deliver_after) if Rpush.config.batch_storage_updates retryable[deliver_after] ||= [] retryable[deliver_after] << notification Rpush::Daemon.store.mark_retryable(notification, deliver_after, :persist => false) else Rpush::Daemon.store.mark_retryable(notification, deliver_after) reflect(:notification_will_retry, notification) end end |
#notification_dispatched ⇒ Object
55 56 57 58 59 60 |
# File 'lib/rpush/daemon/batch.rb', line 55 def notification_dispatched @mutex.synchronize do @num_processed += 1 complete if @num_processed >= @notifications.size end end |
#num_notifications ⇒ Object
18 19 20 |
# File 'lib/rpush/daemon/batch.rb', line 18 def num_notifications @notifications.size end |