lib/sidekiq/metrics/query.rb in sidekiq-6.5.12 vs lib/sidekiq/metrics/query.rb in sidekiq-7.0.0.beta1
- old
+ new
@@ -11,13 +11,13 @@
# Redis and return a Hash of results.
#
# NB: all metrics and times/dates are UTC only. We specifically do not
# support timezones.
class Query
- def initialize(pool: Sidekiq.redis_pool, now: Time.now)
+ def initialize(pool: nil, now: Time.now)
@time = now.utc
- @pool = pool
+ @pool = pool || Sidekiq.default_configuration.redis_pool
@klass = nil
end
# Get metric data for all jobs from the last hour
def top_jobs(minutes: 60)
@@ -121,10 +121,10 @@
end
def series_avg(metric = "ms")
series[metric].each_with_object(Hash.new(0)) do |(bucket, value), result|
completed = series.dig("p", bucket) - series.dig("f", bucket)
- result[bucket] = (completed == 0) ? 0 : value.to_f / completed
+ result[bucket] = completed == 0 ? 0 : value.to_f / completed
end
end
end
class MarkResult < Struct.new(:time, :label)