Class: BackgroundLite::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/background_lite/background.rb

Overview

This class is for configuring defaults of the background processing framework(s) you use. You can configure the frameworks either using the accessors in this class, or by listing them in the config/background.yml configuration file. See Class#background_method for details.

Constant Summary collapse

@@default_handler =

Contains the default background handler that is chosen, if none is specified in the call to Kernel#background.

[:in_process, :forget]
@@default_error_reporter =

Contains the default error reporter.

:stdout
@@slow_threshold =

Time in seconds a job may take before it is logged into slow log. Set to 0 for no logging.

0

Class Method Summary collapse

Class Method Details

.configObject

:nodoc:



31
32
33
# File 'lib/background_lite/background.rb', line 31

def self.config #:nodoc:
  @config ||= YAML.load(File.read("#{Rails.root}/config/background.yml")) rescue { Rails.env => {} }
end

.default_configObject

:nodoc:



35
36
37
38
39
40
41
42
43
# File 'lib/background_lite/background.rb', line 35

def self.default_config #:nodoc:
  @default_config ||= begin
    if config[Rails.env]
      (config[Rails.env]['default'] || config['default'] || {})
    else
      (config['default'] || {})
    end
  end
end

.default_loggerObject

:nodoc:



45
46
47
48
49
50
51
52
53
54
# File 'lib/background_lite/background.rb', line 45

def self.default_logger #:nodoc:
  fallback_logger = if Object.const_defined?("Rails")
    Rails.logger
  else
    logger = Logger.new(STDOUT)
    logger.level = Logger::WARN
    logger
  end
  @@default_logger ||= config['logger'] || fallback_logger
end

.load(configuration) ⇒ Object

:nodoc:



56
57
58
59
60
61
62
63
# File 'lib/background_lite/background.rb', line 56

def self.load(configuration) #:nodoc:
  if configuration.blank?
    default_config
  else
    loaded_config = ((config[Rails.env] || {})[configuration] || {})
    default_config.merge(loaded_config.symbolize_keys || {})
  end
end