Sha256: 7efb8453dd458f9bedcf1b751dbc74b052c2b501df844707d75f83d39b97818e

Contents?: true

Size: 1.07 KB

Versions: 8

Compression:

Stored size: 1.07 KB

Contents

module GoodJob
  class Configuration
    attr_reader :options, :env

    def initialize(options, env: ENV)
      @options = options
      @env = env
    end

    def execution_mode(default: :external)
      if options[:execution_mode]
        options[:execution_mode]
      elsif env['GOOD_JOB_EXECUTION_MODE'].present?
        env['GOOD_JOB_EXECUTION_MODE'].to_sym
      else
        default
      end
    end

    def rails_execution_mode
      if execution_mode(default: nil)
        execution_mode
      elsif Rails.env.development?
        :inline
      elsif Rails.env.test?
        :inline
      else
        :external
      end
    end

    def max_threads
      (
        options[:max_threads] ||
        env['GOOD_JOB_MAX_THREADS'] ||
        env['RAILS_MAX_THREADS'] ||
        ActiveRecord::Base.connection_pool.size
      ).to_i
    end

    def queue_string
      options[:queues] ||
        env['GOOD_JOB_QUEUES'] ||
        '*'
    end

    def poll_interval
      (
        options[:poll_interval] ||
        env['GOOD_JOB_POLL_INTERVAL'] ||
        1
      ).to_i
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
good_job-1.2.3 lib/good_job/configuration.rb
good_job-1.2.2 lib/good_job/configuration.rb
good_job-1.2.1 lib/good_job/configuration.rb
good_job-1.2.0 lib/good_job/configuration.rb
good_job-1.1.4 lib/good_job/configuration.rb
good_job-1.1.3 lib/good_job/configuration.rb
good_job-1.1.2 lib/good_job/configuration.rb
good_job-1.1.1 lib/good_job/configuration.rb