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
#performance_status
Methods included from Taggable
#add_tag, #has_tag?, #remove_tag, #tag_list, #tag_list=
Class Method Details
.ransackable_associations(auth_object = nil) ⇒ Object
22
23
24
|
# File 'app/models/rails_pulse/job.rb', line 22
def self.ransackable_associations(auth_object = nil)
%w[runs]
end
|
.ransackable_attributes(auth_object = nil) ⇒ Object
18
19
20
|
# File 'app/models/rails_pulse/job.rb', line 18
def self.ransackable_attributes(auth_object = nil)
%w[id name queue_name runs_count failures_count retries_count avg_duration p95_duration p99_duration]
end
|
Instance Method Details
#apply_run!(run) ⇒ Object
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
55
56
57
58
59
60
61
62
63
|
# File 'app/models/rails_pulse/job.rb', line 30
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
recent_durations = runs.where.not(duration: nil)
.order(occurred_at: :desc)
.limit(100)
.pluck(:duration)
.sort
updates = {
avg_duration: new_average,
p95_duration: RailsPulse::Statistics.calculate_percentile(recent_durations, 0.95) || 0.0,
p99_duration: RailsPulse::Statistics.calculate_percentile(recent_durations, 0.99) || 0.0
}
updates[:failures_count] = failures_count + 1 if run.failure_like_status?
updates[:retries_count] = retries_count + 1 if run.status == "retried"
update!(updates)
end
end
|
#failure_rate ⇒ Object
65
66
67
68
69
|
# File 'app/models/rails_pulse/job.rb', line 65
def failure_rate
return 0.0 if runs_count.zero?
((failures_count.to_f / runs_count) * 100).round(2)
end
|
#to_breadcrumb ⇒ Object
75
76
77
|
# File 'app/models/rails_pulse/job.rb', line 75
def to_breadcrumb
name.split("/").map(&:camelize).join("::")
end
|
#to_param ⇒ Object
71
72
73
|
# File 'app/models/rails_pulse/job.rb', line 71
def to_param
id.to_s
end
|