class DesmondConfig

manages the gem's configuration

Attributes

is_daemon[R]
logger[RW]

Public Class Methods

add_exception_notifier(&block) click to toggle source

adds the given argument to the list of block to be called when an uncaught exception occurs during job execution

blocks will be called with the arguments (exception, job_class, job_run)

# File lib/desmond.rb, line 79
def self.add_exception_notifier(&block)
  @exception_notifier << block
end
app_id() click to toggle source

retrieves the app_id from the config, defaults to 'desmond'

# File lib/desmond.rb, line 69
def self.app_id
  config['app_id'] || 'desmond'
end
app_id=(value) click to toggle source

change 'app_id' to value only use this in the 'test' environment otherwise the change will not be shared with the worker processes, use the desmond.yml configuration file instead

# File lib/desmond.rb, line 100
def self.app_id=(value)
  fail 'Do not use this DesmondConfig.app_id= outside of "test"' if self.environment != :test
  config['app_id'] = value
end
clear_exception_notifier() click to toggle source
# File lib/desmond.rb, line 82
def self.clear_exception_notifier
  @exception_notifier = []
end
config() click to toggle source

retrieve the desmond configuration

# File lib/desmond.rb, line 61
def self.config
  self.config_file = 'config/desmond.yml' if @config.nil?
  @config
end
config_file=(file) click to toggle source

set where the desmond configuration file is located and reload the configration

# File lib/desmond.rb, line 55
def self.config_file=(file)
  @config = load_config_file(file)
end
database() click to toggle source

retrieve the location of the ActiveRecord database configuration file. should really only be used when developing desmond, otherwise the using app should establish the ActiveRecord connections

# File lib/desmond.rb, line 109
def self.database
  load_config_file(config['database'] || 'config/database.yml')
end
environment() click to toggle source

determins the environment we are running in:

  • development

  • staging

  • production

# File lib/desmond.rb, line 48
def self.environment
  (ENV['RACK_ENV'] || 'development').to_sym
end
register_with_exception_notifier(options={}) click to toggle source
# File lib/desmond.rb, line 85
def self.register_with_exception_notifier(options={})
  options.each do |notifier_name, options|
    ExceptionNotifier.register_exception_notifier(notifier_name, options)
  end
  DesmondConfig.add_exception_notifier do |exception, job_class, job_run|
    ExceptionNotifier.notify_exception(exception, :data => { :class => job_class, run: job_run })
  end
end
system_connection_allowed=(value) click to toggle source

change 'system_connection_allowed' to value only use this in the 'test' environment otherwise the change will not be shared with the worker processes, use the desmond.yml configuration file instead

# File lib/desmond.rb, line 125
def self.system_connection_allowed=(value)
  fail 'Do not use this DesmondConfig.system_connection_allowed= outside of "test"' if self.environment != :test
  config['system_connection_allowed'] = value
end
system_connection_allowed?() click to toggle source

determines whether the tasks are allowed to use the configured connection instead of using the users credentials

# File lib/desmond.rb, line 116
def self.system_connection_allowed?
  config['system_connection_allowed'] || false
end

Private Class Methods

exception_notification(exception, job_class, job_run) click to toggle source
# File lib/desmond.rb, line 141
def self.exception_notification(exception, job_class, job_run)
  @exception_notifier.each do |thing|
    thing.call(exception, job_class, job_run) rescue nil
  end
end
load_config_file(file) click to toggle source
# File lib/desmond.rb, line 130
def self.load_config_file(file)
  return {} unless File.exist?(file)
  ActiveSupport::HashWithIndifferentAccess.new(YAML.load_file(file))
end
set_daemon() click to toggle source
# File lib/desmond.rb, line 136
def self.set_daemon
  @is_daemon = true
end