Class: Resque::Integration::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/resque/integration/configuration.rb

Defined Under Namespace

Classes: Notifier, Worker

Instance Method Summary collapse

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_fileObject



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

#envObject

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_notifierObject

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_fileObject



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_levelObject



208
209
210
# File 'lib/resque/integration/configuration.rb', line 208

def god_log_level
  self['resque.god_log_level'] || 'info'
end

#intervalObject

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_fileObject

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_levelObject

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_fileObject



144
145
146
# File 'lib/resque/integration/configuration.rb', line 144

def pid_file
  "#{pids}/resque-god.pid"
end

#pidsObject



148
149
150
# File 'lib/resque/integration/configuration.rb', line 148

def pids
  self['resque.pids'] || ::Rails.root.join('tmp/pids').to_s
end

#redisOpenStruct

Returns Resque redis configuration

Returns:

  • (OpenStruct)


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

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

#rootObject



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

Returns:

  • (Boolean)


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

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_fileObject

Путь до файла с расписание 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_exceptionsObject

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_timeoutObject

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_godObject

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

#verbosityObject

Returns Resque verbosity level



126
127
128
# File 'lib/resque/integration/configuration.rb', line 126

def verbosity
  (self['resque.verbosity'] || 0).to_i
end

#workersArray<Worker>

Returns workers configuration

Returns:



100
101
102
# File 'lib/resque/integration/configuration.rb', line 100

def workers
  @workers ||= (self[:workers] || {}).map { |k, v| Worker.new(k, v) }
end