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
- #all_processed ⇒ Object
- #complete? ⇒ Boolean
- #each_delivered(&blk) ⇒ Object
- #each_notification(&blk) ⇒ Object
-
#initialize(notifications) ⇒ Batch
constructor
A new instance of Batch.
- #mark_all_delivered ⇒ Object
- #mark_all_failed(code, message) ⇒ Object
- #mark_delivered(notification) ⇒ Object
- #mark_failed(notification, code, description) ⇒ Object
- #mark_retryable(notification, deliver_after) ⇒ Object
- #notification_processed ⇒ Object
Methods included from Reflectable
Constructor Details
#initialize(notifications) ⇒ Batch
Returns a new instance of Batch.
8 9 10 11 12 13 14 15 |
# File 'lib/rpush/daemon/batch.rb', line 8 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
#all_processed ⇒ Object
79 80 81 82 83 84 |
# File 'lib/rpush/daemon/batch.rb', line 79 def all_processed @mutex.synchronize do @num_processed = @notifications.size complete end end |
#complete? ⇒ Boolean
17 18 19 |
# File 'lib/rpush/daemon/batch.rb', line 17 def complete? @complete == true end |
#each_delivered(&blk) ⇒ Object
25 26 27 |
# File 'lib/rpush/daemon/batch.rb', line 25 def each_delivered(&blk) @delivered.each(&blk) end |
#each_notification(&blk) ⇒ Object
21 22 23 |
# File 'lib/rpush/daemon/batch.rb', line 21 def each_notification(&blk) @notifications.each(&blk) end |
#mark_all_delivered ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/rpush/daemon/batch.rb', line 44 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) ⇒ Object
62 63 64 65 66 67 68 69 70 |
# File 'lib/rpush/daemon/batch.rb', line 62 def mark_all_failed(code, ) key = [code, ] @mutex.synchronize do @failed[key] = @notifications end each_notification do |notification| Rpush::Daemon.store.mark_failed(notification, code, , Time.now, persist: false) end end |
#mark_delivered(notification) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/rpush/daemon/batch.rb', line 37 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) ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'lib/rpush/daemon/batch.rb', line 53 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) ⇒ Object
29 30 31 32 33 34 35 |
# 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 ⇒ Object
72 73 74 75 76 77 |
# File 'lib/rpush/daemon/batch.rb', line 72 def notification_processed @mutex.synchronize do @num_processed += 1 complete if @num_processed >= @notifications.size end end |