Sha256: 0c59c69ee09840b0f3550ec6a388b5ea3ce8c4c08d32d57255d65594515b49b7

Contents?: true

Size: 1.45 KB

Versions: 4

Compression:

Stored size: 1.45 KB

Contents

# frozen_string_literal: true

require 'singleton'

module RailsAutoscaleAgent
  class Config
    include Singleton

    attr_accessor :report_interval, :logger, :api_base_url, :max_request_size,
                  :dyno, :pid, :addon_name, :worker_adapters, :dev_mode

    def initialize
      require 'rails_autoscale_agent/worker_adapters/sidekiq'
      require 'rails_autoscale_agent/worker_adapters/delayed_job'
      require 'rails_autoscale_agent/worker_adapters/que'
      require 'rails_autoscale_agent/worker_adapters/resque'
      @worker_adapters = [
        WorkerAdapters::Sidekiq.instance,
        WorkerAdapters::DelayedJob.instance,
        WorkerAdapters::Que.instance,
        WorkerAdapters::Resque.instance,
      ]

      # Allow the add-on name to be configured - needed for testing
      @addon_name = ENV['RAILS_AUTOSCALE_ADDON'] || 'RAILS_AUTOSCALE'
      @api_base_url = ENV["#{@addon_name}_URL"]
      @dev_mode = ENV['RAILS_AUTOSCALE_DEV'] == 'true'
      @pid = Process.pid
      @max_request_size = 100_000 # ignore request payloads over 100k since they skew the queue times
      @report_interval = 10 # this default will be overwritten during Reporter#register!
      @logger ||= defined?(Rails) ? Rails.logger : ::Logger.new(STDOUT)
      @dyno = @dev_mode ? 'dev.1' : ENV['DYNO']
    end

    def to_s
      "#{@dyno}##{@pid}"
    end

    def ignore_large_requests?
      @max_request_size
    end

    alias_method :dev_mode?, :dev_mode
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rails_autoscale_agent-0.9.0.beta.5 lib/rails_autoscale_agent/config.rb
rails_autoscale_agent-0.9.0.beta.4 lib/rails_autoscale_agent/config.rb
rails_autoscale_agent-0.9.0.beta.2 lib/rails_autoscale_agent/config.rb
rails_autoscale_agent-0.9.0.beta.1 lib/rails_autoscale_agent/config.rb