Class: Sidekiq::Throttled::Web::Stats

Inherits:
Object
  • Object
show all
Defined in:
lib/sidekiq/throttled/web/stats.rb

Overview

Throttle strategy stats generation helper

Constant Summary collapse

TIME_CONVERSION =
[
  [60 * 60 * 24,  "day",    "days"],
  [60 * 60,       "hour",   "hours"],
  [60,            "minute", "minutes"],
  [1,             "second", "seconds"]
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(strategy) ⇒ Stats

Returns a new instance of Stats.

Parameters:

  • strategy (Strategy::Concurrency, Strategy::Threshold)

Raises:

  • (ArgumentError)


16
17
18
19
20
# File 'lib/sidekiq/throttled/web/stats.rb', line 16

def initialize(strategy)
  raise ArgumentError, "Can't handle dynamic strategies" if strategy&.dynamic?

  @strategy = strategy
end

Instance Method Details

#to_htmlString

Returns:

  • (String)


23
24
25
26
27
28
29
30
31
# File 'lib/sidekiq/throttled/web/stats.rb', line 23

def to_html
  return "" unless @strategy

  html = humanize_integer(@strategy.limit) << " jobs"

  html << " per " << humanize_duration(@strategy.period) if @strategy.respond_to?(:period)

  html << "<br />" << colorize_count(@strategy.count, @strategy.limit)
end