Class: Resque::UniqueInQueue::Configuration

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

Constant Summary collapse

DEFAULT_IN_QUEUE_KEY_BASE =
'r-uiq'.freeze
DEFAULT_LOCK_AFTER_EXECUTION_PERIOD =
0
DEFAULT_TTL =
-1

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**options) ⇒ Configuration

Returns a new instance of Configuration.



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

def initialize(**options)
  @logger = options.key?(:logger) ? options[:logger] : Logger.new(STDOUT)
  @log_level = options.key?(:log_level) ? options[:log_level] : :debug
  @unique_in_queue_key_base = options.key?(:unique_in_queue_key_base) ? options[:unique_in_queue_key_base] : nil

  # Can be set per each job:
  @lock_after_execution_period = options.key?(:lock_after_execution_period) ? options[:lock_after_execution_period] : DEFAULT_LOCK_AFTER_EXECUTION_PERIOD
  @ttl = options.key?(:ttl) ? options[:ttl] : DEFAULT_TTL
  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?(/in_queue/))
end

Class Attribute Details

.unique_in_queue_key_baseObject

Returns the value of attribute unique_in_queue_key_base.



16
17
18
# File 'lib/resque/unique_in_queue/configuration.rb', line 16

def unique_in_queue_key_base
  @unique_in_queue_key_base
end

Instance Attribute Details

#debug_modeObject

Returns the value of attribute debug_mode.



9
10
11
# File 'lib/resque/unique_in_queue/configuration.rb', line 9

def debug_mode
  @debug_mode
end

#lock_after_execution_periodObject

Returns the value of attribute lock_after_execution_period.



9
10
11
# File 'lib/resque/unique_in_queue/configuration.rb', line 9

def lock_after_execution_period
  @lock_after_execution_period
end

#log_levelObject

Returns the value of attribute log_level.



9
10
11
# File 'lib/resque/unique_in_queue/configuration.rb', line 9

def log_level
  @log_level
end

#loggerObject

Returns the value of attribute logger.



9
10
11
# File 'lib/resque/unique_in_queue/configuration.rb', line 9

def logger
  @logger
end

#ttlObject

Returns the value of attribute ttl.



9
10
11
# File 'lib/resque/unique_in_queue/configuration.rb', line 9

def ttl
  @ttl
end

Instance Method Details

#log(msg) ⇒ Object



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

def log(msg)
  Resque::UniqueInQueue.in_queue_unique_log(msg, self)
end

#to_hashObject



49
50
51
52
53
54
# File 'lib/resque/unique_in_queue/configuration.rb', line 49

def to_hash
  {
    logger: logger,
    log_level: log_level
  }
end

#unique_in_queue_key_baseObject



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

def unique_in_queue_key_base
  @unique_in_queue_key_base || self.class.unique_in_queue_key_base
end

#unique_log_levelObject



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

def unique_log_level
  log_level
end

#unique_loggerObject



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

def unique_logger
  logger
end