Class: Nsqcd::Configuration

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/nsqcd/configuration.rb

Constant Summary collapse

QUEUE_OPTION_DEFAULTS =
{
  topic: 'the-topic',
  channel: 'my-channel',
  nsqlookupd: ['127.0.0.1:4161', '4.5.6.7:4161'],
  max_in_flight: 100,
  discovery_interval: 30,
  msg_timeout: 120_000,
  max_attempts: 10
}.freeze
DEFAULTS =
{
  # Set up default handler which just logs the error.
  # Remove this in production if you don't want sensitive data logged.
  :error_reporters => [Nsqcd::ErrorReporter::DefaultLogger.new],

  # runner
  :runner_config_file => nil,
  :metrics            => nil,
  :daemonize          => false,
  :start_worker_delay => 0.2,
  :workers            => 2,
  :heartbeat          => 300,
  :log                => STDOUT,
  :pid_path           => 'nsqcd.pid',

  # workers
  :prefetch           => 10,
  :threads            => 10,
  :share_threads      => true,
  :ack                => true,
  :hooks              => {},
  :queue_options      => QUEUE_OPTION_DEFAULTS
}.freeze

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



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

def initialize
  clear
end

Instance Method Details

#clearObject



49
50
51
# File 'lib/nsqcd/configuration.rb', line 49

def clear
  @hash = DEFAULTS.dup
end

#deep_merge(first, second) ⇒ Object



65
66
67
68
# File 'lib/nsqcd/configuration.rb', line 65

def deep_merge(first, second)
  merger = proc { |_, v1, v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : v2 }
  first.merge(second, &merger)
end

#merge(hash) ⇒ Object



58
59
60
61
62
63
# File 'lib/nsqcd/configuration.rb', line 58

def merge(hash)
  instance = self.class.new
  instance.merge! to_hash
  instance.merge! hash
  instance
end

#merge!(hash) ⇒ Object



53
54
55
56
# File 'lib/nsqcd/configuration.rb', line 53

def merge!(hash)
  hash = hash.dup
  @hash = deep_merge(@hash, hash)
end