Class: BanterMessage
- Inherits:
-
Object
- Object
- BanterMessage
- Includes:
- Mongoid::Document
- Defined in:
- lib/banter/web/models/banter_message.rb
Constant Summary collapse
- STATUS_STARTED =
'started'
- STATUS_SUCCESS =
'success'
- STATUS_ERROR =
'error'
- STATUS_VALIDATION_FAILED =
'validation_failed'
Class Method Summary collapse
-
.message_failed(error, status) ⇒ Object
Records the current message as errored or validation failed with error message.
-
.message_received(subscriber_class, worker, payload) ⇒ Object
Creates a BanterMessage to record a message that is received by a subscriber.
-
.message_successful ⇒ Object
Records the current message as successful.
- .update_progress(object) ⇒ Object
-
.update_progress_at(num) ⇒ Object
Records the current progress as a number for the current message.
-
.update_progress_total(num) ⇒ Object
Records the number of objects expected to be processed for the current message.
Instance Method Summary collapse
- #executing? ⇒ Boolean
- #failed? ⇒ Boolean
- #succeeded? ⇒ Boolean
-
#worker ⇒ BanterWorker
The worker that is responsible for executing the current message.
Class Method Details
.message_failed(error, status) ⇒ Object
Records the current message as errored or validation failed with error message. Clears the BanterMessage.current
75 76 77 78 79 80 81 82 83 |
# File 'lib/banter/web/models/banter_message.rb', line 75 def self.(error, status) current.status = status current.done_at = Time.now current. = error. current.error_backtrace = error.backtrace current.save! BanterWorker.(false) @@current = nil end |
.message_received(subscriber_class, worker, payload) ⇒ Object
Creates a BanterMessage to record a message that is received by a subscriber. It records the created message as BanterMessage.current
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/banter/web/models/banter_message.rb', line 41 def self.(subscriber_class, worker, payload) return unless BanterWorker.current obj = new( subscriber_class: subscriber_class.name, queue_name: subscriber_class.subscribed_queue, subscribed_key: subscriber_class.subscribed_key, payload_key: worker.routing_key, # routing_data: worker.delivery_routing_data.to_hash, # properties: worker.delivery_properties.to_hash, payload: payload, context: worker.context, started_at: Time.now, status: STATUS_STARTED, worker_id: BanterWorker.current.id ) obj.save! @@current = obj BanterWorker.record_current!(obj) end |
.message_successful ⇒ Object
Records the current message as successful. Clears the BanterMessage.current
64 65 66 67 68 69 70 |
# File 'lib/banter/web/models/banter_message.rb', line 64 def self. current.status = STATUS_SUCCESS current.done_at = Time.now current.save! BanterWorker.(true) @@current = nil end |
.update_progress(object) ⇒ Object
102 103 104 105 106 |
# File 'lib/banter/web/models/banter_message.rb', line 102 def self.update_progress(object) return unless current current.progress = object current.save! end |
.update_progress_at(num) ⇒ Object
Records the current progress as a number for the current message.
87 88 89 90 91 |
# File 'lib/banter/web/models/banter_message.rb', line 87 def self.update_progress_at(num) return unless current current.progress_at = num current.save! end |
.update_progress_total(num) ⇒ Object
Records the number of objects expected to be processed for the current message.
95 96 97 98 99 |
# File 'lib/banter/web/models/banter_message.rb', line 95 def self.update_progress_total(num) return unless current current.progress_total = num current.save! end |
Instance Method Details
#executing? ⇒ Boolean
108 109 110 |
# File 'lib/banter/web/models/banter_message.rb', line 108 def executing? self.status == STATUS_STARTED end |
#failed? ⇒ Boolean
116 117 118 |
# File 'lib/banter/web/models/banter_message.rb', line 116 def failed? self.status == STATUS_ERROR || self.status == STATUS_VALIDATION_FAILED end |
#succeeded? ⇒ Boolean
112 113 114 |
# File 'lib/banter/web/models/banter_message.rb', line 112 def succeeded? self.status == STATUS_SUCCESS end |
#worker ⇒ BanterWorker
Returns The worker that is responsible for executing the current message.
121 122 123 |
# File 'lib/banter/web/models/banter_message.rb', line 121 def worker @worker ||= BanterWorker.find(self['worker_id'].to_s) end |