Class: Rearview::ResultsHandler
- Inherits:
-
Object
- Object
- Rearview::ResultsHandler
- Includes:
- Logger
- Defined in:
- lib/rearview/results_handler.rb
Instance Attribute Summary collapse
-
#job ⇒ Object
readonly
Returns the value of attribute job.
-
#monitor_results ⇒ Object
readonly
Returns the value of attribute monitor_results.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
-
#initialize(job, monitor_results) ⇒ ResultsHandler
constructor
A new instance of ResultsHandler.
- #run ⇒ Object
Methods included from Logger
Constructor Details
#initialize(job, monitor_results) ⇒ ResultsHandler
Returns a new instance of ResultsHandler.
6 7 8 9 10 |
# File 'lib/rearview/results_handler.rb', line 6 def initialize(job,monitor_results) @job = job @status = Job::Status::ERROR @monitor_results = monitor_results || {} end |
Instance Attribute Details
#job ⇒ Object (readonly)
Returns the value of attribute job.
4 5 6 |
# File 'lib/rearview/results_handler.rb', line 4 def job @job end |
#monitor_results ⇒ Object (readonly)
Returns the value of attribute monitor_results.
4 5 6 |
# File 'lib/rearview/results_handler.rb', line 4 def monitor_results @monitor_results end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
4 5 6 |
# File 'lib/rearview/results_handler.rb', line 4 def status @status end |
Instance Method Details
#run ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/rearview/results_handler.rb', line 11 def run logger.info "#{self} run" normalized_results = Rearview::MonitorRunner.normalize_results(@monitor_results) @status = normalized_results[:status] || @status job_data = JobData.find_or_create_by(job_id: @job.id) job_data.data = normalized_results job_data.save! @job.last_run = Time.now.utc event = if Job::Status.values.include?(@status.to_s) @status.to_sym else :error end logger.info "#{self} firing event :#{event} for #{@job.inspect}" @job.fire_event(event,{:monitor_results=>@monitor_results,:job_error=>{:message=>normalized_results[:output]}}) self rescue logger.error "#{self} process results failed: #{$!}\n#{$@.join("\n")}" self end |