Sha256: d025b5b1fd6268d9b01a3d654e7146d19881ba5b102c8fffa5c0ba4b8f0be5cc

Contents?: true

Size: 785 Bytes

Versions: 3

Compression:

Stored size: 785 Bytes

Contents

require 'active_support/core_ext/numeric'

module RooOnRails
  module Sidekiq
    class QueueLatency
      extend Forwardable

      def_delegators :@queue, :size, :latency, :name
      attr_reader :queue

      def initialize(queue)
        @queue = queue
      end

      def normalised_latency
        metric = queue.latency.to_f / permitted_latency
        metric.round(3)
      end

      def permitted_latency
        prefix, number, unit = queue.name.partition(/[0-9]+/)
        case prefix
        when 'monitoring', 'realtime' then 10.seconds.to_i
        when 'default' then 1.day.to_i
        when 'within' then number.to_i.public_send(unit.to_sym).to_i
        else raise "Cannot determine permitted latency for queue #{queue.name}"
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
roo_on_rails-1.7.0 lib/roo_on_rails/sidekiq/queue_latency.rb
roo_on_rails-1.6.0 lib/roo_on_rails/sidekiq/queue_latency.rb
roo_on_rails-1.5.0 lib/roo_on_rails/sidekiq/queue_latency.rb