Class: RailsPulse::JobRun

Inherits:
ApplicationRecord show all
Includes:
Taggable
Defined in:
app/models/rails_pulse/job_run.rb

Constant Summary collapse

STATUSES =
%w[enqueued running success failed discarded retried].freeze
FINAL_STATUSES =
%w[success failed discarded retried].freeze

Constants included from Taggable

Taggable::MAX_TAG_LENGTH, Taggable::TAG_NAME_REGEX

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Taggable

#add_tag, #has_tag?, #remove_tag, #tag_list, #tag_list=

Class Method Details

.ransackable_associations(auth_object = nil) ⇒ Object



28
29
30
# File 'app/models/rails_pulse/job_run.rb', line 28

def self.ransackable_associations(auth_object = nil)
  %w[job operations]
end

.ransackable_attributes(auth_object = nil) ⇒ Object



24
25
26
# File 'app/models/rails_pulse/job_run.rb', line 24

def self.ransackable_attributes(auth_object = nil)
  %w[id job_id run_id status occurred_at duration attempts adapter]
end

Instance Method Details

#all_tagsObject



39
40
41
# File 'app/models/rails_pulse/job_run.rb', line 39

def all_tags
  (job.tag_list + tag_list).uniq
end

#failure_like_status?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'app/models/rails_pulse/job_run.rb', line 58

def failure_like_status?
  FINAL_STATUSES.include?(status) && status != "success"
end

#finalized?Boolean

Returns:

  • (Boolean)


62
63
64
65
66
67
68
# File 'app/models/rails_pulse/job_run.rb', line 62

def finalized?
  change = previous_changes["status"]
  return false unless change

  previous_state, new_state = change
  FINAL_STATUSES.include?(new_state) && !FINAL_STATUSES.include?(previous_state)
end

#performance_statusObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/models/rails_pulse/job_run.rb', line 43

def performance_status
  thresholds = RailsPulse.configuration.job_thresholds
  duration = self.duration.to_f

  if duration < thresholds[:slow]
    :fast
  elsif duration < thresholds[:very_slow]
    :slow
  elsif duration < thresholds[:critical]
    :very_slow
  else
    :critical
  end
end