Class: Rearview::JobError

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
ConstantsModuleMaker, Ext::StateMachine
Defined in:
app/models/rearview/job_error.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Ext::StateMachine

#fire_event

Methods included from ConstantsModuleMaker

included

Instance Attribute Details

#end_dateObject

Returns the value of attribute end_date.



14
15
16
# File 'app/models/rearview/job_error.rb', line 14

def end_date
  @end_date
end

Class Method Details

.application_errors(application_id) ⇒ Object



91
92
93
# File 'app/models/rearview/job_error.rb', line 91

def self.application_errors(application_id)
  joins("INNER JOIN jobs ON jobs.id = job_errors.job_id").joins("INNER JOIN applications ON applications.id = jobs.app_id").where("applications.id = ?",application_id)
end

.calculate_durations(errors) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'app/models/rearview/job_error.rb', line 77

def self.calculate_durations(errors)
  last_with_error = nil         # most recently found error
  (errors.each do |e|
    if e.status == Status::SUCCESS
      unless last_with_error.nil?
        last_with_error.end_date = e.created_at.utc.to_i
        last_with_error = nil
      end
    else
      last_with_error = e
    end
  end).reject { |e| e.status == Status::SUCCESS }
end

.last_error(job_id) ⇒ Object



95
96
97
# File 'app/models/rearview/job_error.rb', line 95

def self.last_error(job_id)
  only_errors.where("job_id = ?",job_id).order_created.limit(1).first
end

.latest_entry(job_id) ⇒ Object



99
100
101
# File 'app/models/rearview/job_error.rb', line 99

def self.latest_entry(job_id)
  where("job_id = ?",job_id).order_created.limit(1).first
end

.search(params) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'app/models/rearview/job_error.rb', line 57

def self.search(params)
  filter = self.where(:job_id=>params[:id])
  order_direction = "DESC"
  if params[:start_date]
    filter = filter.where("created_at >= ?",params[:start_date])
    order_direction = "ASC"
  end
  if params[:end_date]
    filter = filter.where("created_at <= ?",params[:end_date])
    order_direction = "ASC"
  end
  if params[:limit]
    filter = filter.limit(params[:limit])
  end
  if params[:offset]
    filter = filter.offset(params[:offset])
  end
  filter.order("created_at #{order_direction}")
end

Instance Method Details

#create_alert(transition) ⇒ Object



103
104
105
106
107
# File 'app/models/rearview/job_error.rb', line 103

def create_alert(transition)
  Rearview::AlertsHandler.new(self.job,event_data[:monitor_results]).run
  self.last_alerted_at = Time.now.utc
  save!
end

#update_alert(transition) ⇒ Object



109
110
111
112
113
114
115
# File 'app/models/rearview/job_error.rb', line 109

def update_alert(transition)
  if !self.last_alerted_at || Time.now.utc >= self.last_alerted_at.utc + self.job.error_timeout.minutes
    Rearview::AlertsHandler.new(self.job,event_data[:monitor_results]).run
    self.last_alerted_at = Time.now.utc
    save!
  end
end