class DesmondConfig
manages the gem's configuration
Attributes
Public Class Methods
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
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
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
# File lib/desmond.rb, line 82 def self.clear_exception_notifier @exception_notifier = [] end
retrieve the desmond configuration
# File lib/desmond.rb, line 61 def self.config self.config_file = 'config/desmond.yml' if @config.nil? @config end
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
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
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
# 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
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
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
# 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
# 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
# File lib/desmond.rb, line 136 def self.set_daemon @is_daemon = true end