Class: SolidQueueWeb::JobPerformanceStats
- Inherits:
-
Object
- Object
- SolidQueueWeb::JobPerformanceStats
- Defined in:
- app/services/solid_queue_web/job_performance_stats.rb
Defined Under Namespace
Classes: Row
Instance Method Summary collapse
-
#initialize(scope) ⇒ JobPerformanceStats
constructor
A new instance of JobPerformanceStats.
- #rows ⇒ Object
Constructor Details
#initialize(scope) ⇒ JobPerformanceStats
Returns a new instance of JobPerformanceStats.
5 6 7 |
# File 'app/services/solid_queue_web/job_performance_stats.rb', line 5 def initialize(scope) @scope = scope end |
Instance Method Details
#rows ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/services/solid_queue_web/job_performance_stats.rb', line 9 def rows grouped = @scope.pluck(:class_name, :created_at, :finished_at) .group_by(&:first) grouped.map do |class_name, records| durations = records.map { |_, created, finished| (finished - created).to_f }.sort Row.new( class_name: class_name, count: durations.size, avg: mean(durations), p50: percentile(durations, 50), p95: percentile(durations, 95), min: durations.first, max: durations.last ) end.sort_by { |r| -r.p95 } end |