Class: DesmondConfig

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

Overview

manages the gem’s configuration

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.is_daemonObject (readonly)

Returns the value of attribute is_daemon.



39
40
41
# File 'lib/desmond.rb', line 39

def is_daemon
  @is_daemon
end

.loggerObject

Returns the value of attribute logger.



38
39
40
# File 'lib/desmond.rb', line 38

def logger
  @logger
end

Class Method Details

.add_exception_notifier(&block) ⇒ Object

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)



79
80
81
# File 'lib/desmond.rb', line 79

def self.add_exception_notifier(&block)
  @exception_notifier << block
end

.app_idObject

retrieves the app_id from the config, defaults to ‘desmond’



69
70
71
# File 'lib/desmond.rb', line 69

def self.app_id
  config['app_id'] || 'desmond'
end

.app_id=(value) ⇒ Object

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



100
101
102
103
# 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_notifierObject



82
83
84
# File 'lib/desmond.rb', line 82

def self.clear_exception_notifier
  @exception_notifier = []
end

.configObject

retrieve the desmond configuration



61
62
63
64
# File 'lib/desmond.rb', line 61

def self.config
  self.config_file = 'config/desmond.yml' if @config.nil?
  @config
end

.config_file=(file) ⇒ Object

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



55
56
57
# File 'lib/desmond.rb', line 55

def self.config_file=(file)
  @config = load_config_file(file)
end

.databaseObject

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



109
110
111
# File 'lib/desmond.rb', line 109

def self.database
  load_config_file(config['database'] || 'config/database.yml')
end

.environmentObject

determins the environment we are running in:

  • development

  • staging

  • production



48
49
50
# File 'lib/desmond.rb', line 48

def self.environment
  (ENV['RACK_ENV'] || 'development').to_sym
end

.register_with_exception_notifier(options = {}) ⇒ Object



85
86
87
88
89
90
91
92
# 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) ⇒ Object

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



125
126
127
128
# 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?Boolean

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

Returns:

  • (Boolean)


116
117
118
# File 'lib/desmond.rb', line 116

def self.system_connection_allowed?
  config['system_connection_allowed'] || false
end