Class: Resque::Integration::Configuration
- Inherits:
-
Object
- Object
- Resque::Integration::Configuration
- Defined in:
- lib/resque/integration/configuration.rb
Defined Under Namespace
Instance Method Summary collapse
- #config_file ⇒ Object
-
#env ⇒ Object
Returns environment variables that should be associated with this configuration.
-
#failure_notifier ⇒ Object
Returns failure notifier config.
- #god_log_file ⇒ Object
- #god_log_level ⇒ Object
-
#initialize(*paths) ⇒ Configuration
constructor
Create configuration from given
paths
. -
#interval ⇒ Object
Returns Resque polling interval.
-
#log_file ⇒ Object
Returns path to resque log file.
-
#log_level ⇒ Object
Returns Resque log level.
- #pid_file ⇒ Object
- #pids ⇒ Object
-
#redis ⇒ OpenStruct
Returns Resque redis configuration.
-
#resque_scheduler? ⇒ Boolean
Используется ли resque scheduler.
- #root ⇒ Object
-
#run_at_exit_hooks? ⇒ Boolean
Returns flag for cleaning on shutdown see github.com/resque/resque/issues/1167.
-
#schedule_exists? ⇒ Boolean
Есть ли расписание у приложения?.
-
#schedule_file ⇒ Object
Путь до файла с расписание resque schedule.
-
#temporary_exceptions ⇒ Object
Public: Temporary exceptions.
-
#terminate_timeout ⇒ Object
Returns maximum terminate timeout.
-
#to_god ⇒ Object
Generate GOD configuration file.
-
#verbosity ⇒ Object
Returns Resque verbosity level.
-
#workers ⇒ Array<Worker>
Returns workers configuration.
Constructor Details
#initialize(*paths) ⇒ Configuration
Create configuration from given paths
85 86 87 88 |
# File 'lib/resque/integration/configuration.rb', line 85 def initialize(*paths) @configuration = {} paths.each { |f| load f } end |
Instance Method Details
#config_file ⇒ Object
140 141 142 |
# File 'lib/resque/integration/configuration.rb', line 140 def config_file self['resque.config_file'] || ::Rails.root.join('config/resque.god').to_s end |
#env ⇒ Object
Returns environment variables that should be associated with this configuration
190 191 192 193 194 195 196 |
# File 'lib/resque/integration/configuration.rb', line 190 def env env = self['env'] || {} env[:INTERVAL] ||= interval Hash[env.map { |k, v| [k, v.to_s] }] end |
#failure_notifier ⇒ Object
Returns failure notifier config
105 106 107 |
# File 'lib/resque/integration/configuration.rb', line 105 def failure_notifier @notifier ||= Notifier.new(self['failure.notifier']) end |
#god_log_file ⇒ Object
204 205 206 |
# File 'lib/resque/integration/configuration.rb', line 204 def god_log_file self['resque.god_log_file'] || ::Rails.root.join('log/god.log').to_s end |
#god_log_level ⇒ Object
208 209 210 |
# File 'lib/resque/integration/configuration.rb', line 208 def god_log_level self['resque.god_log_level'] || 'info' end |
#interval ⇒ Object
Returns Resque polling interval
121 122 123 |
# File 'lib/resque/integration/configuration.rb', line 121 def interval (self['resque.interval'] || 5).to_i end |
#log_file ⇒ Object
Returns path to resque log file
136 137 138 |
# File 'lib/resque/integration/configuration.rb', line 136 def log_file self['resque.log_file'] || ::Rails.root.join('log/resque.log').to_s end |
#log_level ⇒ Object
Returns Resque log level
131 132 133 |
# File 'lib/resque/integration/configuration.rb', line 131 def log_level (self['resque.log_level'] || 1).to_i end |
#pid_file ⇒ Object
144 145 146 |
# File 'lib/resque/integration/configuration.rb', line 144 def pid_file "#{pids}/resque-god.pid" end |
#pids ⇒ Object
148 149 150 |
# File 'lib/resque/integration/configuration.rb', line 148 def pids self['resque.pids'] || ::Rails.root.join('tmp/pids').to_s end |
#redis ⇒ OpenStruct
Returns Resque redis configuration
93 94 95 |
# File 'lib/resque/integration/configuration.rb', line 93 def redis @redis ||= (self['redis'] || {}).symbolize_keys end |
#resque_scheduler? ⇒ Boolean
Используется ли resque scheduler
Returns boolean
174 175 176 177 178 179 180 181 182 |
# File 'lib/resque/integration/configuration.rb', line 174 def resque_scheduler? value = self['resque.scheduler'] || true if value.is_a?(String) && %w(n no false off disabled).include?(value) value = false end value end |
#root ⇒ Object
152 153 154 |
# File 'lib/resque/integration/configuration.rb', line 152 def root self['resque.root'] || ::Rails.root.to_s end |
#run_at_exit_hooks? ⇒ Boolean
Returns flag for cleaning on shutdown see github.com/resque/resque/issues/1167
110 111 112 113 114 115 116 117 118 |
# File 'lib/resque/integration/configuration.rb', line 110 def run_at_exit_hooks? value = self['resque.run_at_exit_hooks'] if value.is_a?(String) && %w(n no false off disabled).include?(value) value = false end value.nil? ? true : value end |
#schedule_exists? ⇒ Boolean
Есть ли расписание у приложения?
Returns boolean
166 167 168 169 |
# File 'lib/resque/integration/configuration.rb', line 166 def schedule_exists? return @schedule_exists if defined?(@schedule_exists) @schedule_exists = File.exist?(schedule_file) end |
#schedule_file ⇒ Object
Путь до файла с расписание resque schedule
Returns String
159 160 161 |
# File 'lib/resque/integration/configuration.rb', line 159 def schedule_file self['resque.schedule_file'] || ::Rails.root.join('config', 'resque_schedule.yml') end |
#temporary_exceptions ⇒ Object
Public: Temporary exceptions.
Examples
temporary_exceptions
# => {PG::TRDeadlockDetected => 20, Net::OpenTimeout => 123}
Returns Hash.
220 221 222 223 224 225 226 227 228 |
# File 'lib/resque/integration/configuration.rb', line 220 def temporary_exceptions return @temporary_exceptions if defined?(@temporary_exceptions) return {} unless self['resque.temporary_exceptions'] @temporary_exceptions = self['resque.temporary_exceptions'].each_with_object({}) do |(key, value), result| result[key.constantize] = value end end |
#terminate_timeout ⇒ Object
Returns maximum terminate timeout
185 186 187 |
# File 'lib/resque/integration/configuration.rb', line 185 def terminate_timeout workers.map(&:stop_timeout).compact.max.to_i + 10 end |
#to_god ⇒ Object
Generate GOD configuration file
199 200 201 202 |
# File 'lib/resque/integration/configuration.rb', line 199 def to_god template = ERB.new(File.read(File.join(File.dirname(__FILE__), 'god.erb'))) template.result(binding) end |
#verbosity ⇒ Object
Returns Resque verbosity level
126 127 128 |
# File 'lib/resque/integration/configuration.rb', line 126 def verbosity (self['resque.verbosity'] || 0).to_i end |