Class: Resque::UniqueAtRuntime::Configuration

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

Constant Summary collapse

DEFAULT_AT_RUNTIME_KEY_BASE =
'r-uae'
DEFAULT_LOCK_TIMEOUT =
60 * 60 * 24 * 5
DEFAULT_REQUEUE_INTERVAL =
1

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**options) ⇒ Configuration

Returns a new instance of Configuration.



23
24
25
26
27
28
29
30
31
# File 'lib/resque/unique_at_runtime/configuration.rb', line 23

def initialize(**options)
  @logger = options.key?(:logger) ? options[:logger] : Logger.new(STDOUT)
  @log_level = options.key?(:log_level) ? options[:log_level] : :debug
  @unique_at_runtime_key_base = options.key?(:unique_at_runtime_key_base) ? options[:unique_at_runtime_key_base] : nil
  @lock_timeout = options.key?(:lock_timeout) ? options[:lock_timeout] : DEFAULT_LOCK_TIMEOUT
  @requeue_interval = options.key?(:requeue_interval) ? options[:requeue_interval] : DEFAULT_REQUEUE_INTERVAL
  env_debug = ENV['RESQUE_DEBUG']
  @debug_mode = !!(options.key?(:debug_mode) ? options[:debug_mode] : env_debug == 'true' || (env_debug.is_a?(String) && env_debug.match?(/runtime/)))
end

Class Attribute Details

.unique_at_runtime_key_baseObject

Returns the value of attribute unique_at_runtime_key_base.



18
19
20
# File 'lib/resque/unique_at_runtime/configuration.rb', line 18

def unique_at_runtime_key_base
  @unique_at_runtime_key_base
end

Instance Attribute Details

#debug_modeObject

Returns the value of attribute debug_mode.



11
12
13
# File 'lib/resque/unique_at_runtime/configuration.rb', line 11

def debug_mode
  @debug_mode
end

#lock_timeoutObject

Returns the value of attribute lock_timeout.



11
12
13
# File 'lib/resque/unique_at_runtime/configuration.rb', line 11

def lock_timeout
  @lock_timeout
end

#log_levelObject

Returns the value of attribute log_level.



11
12
13
# File 'lib/resque/unique_at_runtime/configuration.rb', line 11

def log_level
  @log_level
end

#loggerObject

Returns the value of attribute logger.



11
12
13
# File 'lib/resque/unique_at_runtime/configuration.rb', line 11

def logger
  @logger
end

#requeue_intervalObject

Returns the value of attribute requeue_interval.



11
12
13
# File 'lib/resque/unique_at_runtime/configuration.rb', line 11

def requeue_interval
  @requeue_interval
end

Instance Method Details

#log(msg) ⇒ Object



41
42
43
# File 'lib/resque/unique_at_runtime/configuration.rb', line 41

def log(msg)
  Resque::UniqueAtRuntime.runtime_unique_log(msg, self)
end

#to_hashObject



49
50
51
52
53
54
55
56
57
58
# File 'lib/resque/unique_at_runtime/configuration.rb', line 49

def to_hash
  {
    logger: logger,
    log_level: log_level,
    debug_mode: debug_mode,
    unique_at_runtime_key_base: unique_at_runtime_key_base,
    lock_timeout: lock_timeout,
    requeue_interval: requeue_interval
  }
end

#unique_at_runtime_key_baseObject



45
46
47
# File 'lib/resque/unique_at_runtime/configuration.rb', line 45

def unique_at_runtime_key_base
  @unique_at_runtime_key_base || self.class.unique_at_runtime_key_base
end

#unique_log_levelObject



37
38
39
# File 'lib/resque/unique_at_runtime/configuration.rb', line 37

def unique_log_level
  log_level
end

#unique_loggerObject



33
34
35
# File 'lib/resque/unique_at_runtime/configuration.rb', line 33

def unique_logger
  logger
end