Class: RailsPulse::Job
Constant Summary
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
19
20
21
|
# File 'app/models/rails_pulse/job.rb', line 19
def self.ransackable_associations(auth_object = nil)
%w[runs]
end
|
.ransackable_attributes(auth_object = nil) ⇒ Object
15
16
17
|
# File 'app/models/rails_pulse/job.rb', line 15
def self.ransackable_attributes(auth_object = nil)
%w[id name queue_name runs_count failures_count retries_count avg_duration]
end
|
Instance Method Details
#apply_run!(run) ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'app/models/rails_pulse/job.rb', line 27
def apply_run!(run)
return unless run.duration
duration = run.duration.to_f
with_lock do
reload
total_runs = runs_count.to_i
previous_total = [ total_runs - 1, 0 ].max
previous_average = avg_duration.to_f
new_average = if previous_total.zero?
duration
else
((previous_average * previous_total) + duration) / (previous_total + 1)
end
updates = { avg_duration: new_average }
if run.failure_like_status?
updates[:failures_count] = failures_count + 1
end
if run.status == "retried"
updates[:retries_count] = retries_count + 1
end
update!(updates)
end
end
|
#failure_rate ⇒ Object
56
57
58
59
60
|
# File 'app/models/rails_pulse/job.rb', line 56
def failure_rate
return 0.0 if runs_count.zero?
((failures_count.to_f / runs_count) * 100).round(2)
end
|
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'app/models/rails_pulse/job.rb', line 62
def performance_status
thresholds = RailsPulse.configuration.job_thresholds
duration = avg_duration.to_f
if duration < thresholds[:slow]
:fast
elsif duration < thresholds[:very_slow]
:slow
elsif duration < thresholds[:critical]
:very_slow
else
:critical
end
end
|
#to_breadcrumb ⇒ Object
81
82
83
|
# File 'app/models/rails_pulse/job.rb', line 81
def to_breadcrumb
name
end
|
#to_param ⇒ Object
77
78
79
|
# File 'app/models/rails_pulse/job.rb', line 77
def to_param
id.to_s
end
|