Module: AutomateEm::Status
Instance Attribute Summary collapse
-
#status ⇒ Object
readonly
Should not be accessed like this for modification.
Instance Method Summary collapse
- #[](status) ⇒ Object
- #[]=(status, data) ⇒ Object
- #mark_emit_end ⇒ Object
- #mark_emit_start(status) ⇒ Object
- #update_status(status, &block) ⇒ Object
Instance Attribute Details
#status ⇒ Object (readonly)
Should not be accessed like this for modification
40 41 42 |
# File 'lib/automate-em/status.rb', line 40 def status @status end |
Instance Method Details
#[](status) ⇒ Object
7 8 9 10 11 12 |
# File 'lib/automate-em/status.rb', line 7 def [] (status) status = status.to_sym if status.class == String @status_lock.mon_synchronize { return @status[status] } end |
#[]=(status, data) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/automate-em/status.rb', line 14 def []= (status, data) status = status.to_sym if status.class == String @status_lock.mon_synchronize { old_data = check_for_emit(status, data) if data != old_data changed # so that the notify is applied logger.debug "#{self.class} status updated: #{status} = #{data}" end notify_observers(self, status, data) # only notify changes } end |
#mark_emit_end ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/automate-em/status.rb', line 49 def mark_emit_end @status_lock.mon_synchronize { @emit_hasnt_occured.each_pair do | key, block | data = @status[key] task do begin block.call(data) ensure ActiveRecord::Base.clear_active_connections! end end logger.debug "A forced emit on #{status} occured" end @emit_hasnt_occured = nil } end |
#mark_emit_start(status) ⇒ Object
43 44 45 46 47 |
# File 'lib/automate-em/status.rb', line 43 def mark_emit_start(status) @status_lock.mon_synchronize { @emit_hasnt_occured = status } end |
#update_status(status, &block) ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/automate-em/status.rb', line 29 def update_status(status, &block) status = status.to_sym if status.class == String @status_lock.mon_synchronize { data = @status[status] data = data.clone unless data.nil? newValue = block.call(data) self[status] = newValue return @status[status] } end |