Class: MagistrateMonitor::Supervisor
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- MagistrateMonitor::Supervisor
- Defined in:
- lib/magistrate_monitor/supervisor.rb
Instance Method Summary collapse
-
#databag_for(worker) ⇒ Object
This method abstracts access to a worker’s databag.
- #normalize_databag_for!(worker) ⇒ Object
-
#normalize_status_data! ⇒ Object
This makes sure that: All supervisors have a status that is a hash If it has something else for whatever reason, the real object is put in a hash under the ‘status’ key.
- #set_target_state!(action, worker) ⇒ Object
Instance Method Details
#databag_for(worker) ⇒ Object
This method abstracts access to a worker’s databag. It guarantees to return a hash of some sort useful for referencing worker properties However, changes to this hash may not be propegated back. Quite possibly it would be better to do checking here like in set_target_state! to normalize the data?
35 36 37 |
# File 'lib/magistrate_monitor/supervisor.rb', line 35 def databag_for(worker) (self.databag['workers'].is_a?(Hash) ? self.databag['workers'][worker] : {}) || {} end |
#normalize_databag_for!(worker) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/magistrate_monitor/supervisor.rb', line 25 def normalize_databag_for!(worker) d = self.databag || {} d['workers'] ||= {} d['workers'][worker] ||= {} self.databag = d end |
#normalize_status_data! ⇒ Object
This makes sure that: All supervisors have a status that is a hash If it has something else for whatever reason, the real object is put in a hash under the ‘status’ key
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/magistrate_monitor/supervisor.rb', line 11 def normalize_status_data! self.status ||= {} self.status['workers'] ||= {} self.status['workers'].each do |k,v| unless v.is_a?(Hash) v = {'state' => v.inspect } end end self.databag ||= {} self.databag['workers'] ||= {} end |
#set_target_state!(action, worker) ⇒ Object
39 40 41 42 43 |
# File 'lib/magistrate_monitor/supervisor.rb', line 39 def set_target_state!(action, worker) normalize_databag_for!(worker) self.databag['workers'][worker]['target_state'] = action self.update_attribute :databag, self.databag end |