Sha256: 8b7dba0a9ada105629efcaefdc7465ee1f4b965dfd9525b67bec30019b3b608c

Contents?: true

Size: 843 Bytes

Versions: 5

Compression:

Stored size: 843 Bytes

Contents

# frozen_string_literal: true

require 'sidekiq'

module SidekiqHerokuScaler
  class Worker
    def initialize(worker_name, formation)
      @worker_name = worker_name
      @formation = formation
    end

    def concurrency
      process['concurrency'] || 0
    end

    def formation_id
      formation.id
    end

    def quantity
      formation.quantity
    end

    def latency
      queues.sum { |queue| Sidekiq::Queue.new(queue).latency }
    end

    def queues_size
      queues.sum { |queue| Sidekiq::Queue.new(queue).size }
    end

    private

    attr_reader :formation, :worker_name

    def queues
      process['queues'] || []
    end

    def process_set
      @process_set ||= Sidekiq::ProcessSet.new
    end

    def process
      process_set.detect { |p| p.identity.match(/\A#{worker_name}\./) } || {}
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
sidekiq-heroku-scaler-0.2.0 lib/sidekiq-heroku-scaler/worker.rb
sidekiq-heroku-scaler-0.1.5 lib/sidekiq-heroku-scaler/worker.rb
sidekiq-heroku-scaler-0.1.4 lib/sidekiq-heroku-scaler/worker.rb
sidekiq-heroku-scaler-0.1.3 lib/sidekiq-heroku-scaler/worker.rb
sidekiq-heroku-scaler-0.1.0 lib/sidekiq-heroku-scaler/worker.rb