Class: PikaQue::Configuration

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

Constant Summary collapse

EXCHANGE_OPTION_DEFAULTS =
{
  :type               => :direct,
  :durable            => true,
  :auto_delete        => false,
  :arguments => {} # Passed as :arguments to Bunny::Channel#exchange
}.freeze
QUEUE_OPTION_DEFAULTS =
{
  :durable            => true,
  :auto_delete        => false,
  :exclusive          => false,
  :arguments => {}
}.freeze
CHANNEL_OPTION_DEFAULTS =
{
  :consumer_pool_size => 1,
  :prefetch           => 10
}.freeze
DELAY_PROCESSOR_DEFAULTS =
{
  :workers            => [PikaQue::DelayWorker],
  :handler_class      => PikaQue::Handlers::DelayHandler,
  :concurrency        => 1
}.freeze
DEFAULT_CONFIG =
{
  :exchange           => 'pika-que',
  :heartbeat          => 30,
  :channel_options    => CHANNEL_OPTION_DEFAULTS,
  :exchange_options   => EXCHANGE_OPTION_DEFAULTS,
  :queue_options      => QUEUE_OPTION_DEFAULTS,
  :concurrency        => 1,
  :ack                => true,
  :handler_class      => PikaQue::Handlers::DefaultHandler,
  :handler_options    => {},
  :codec              => PikaQue::Codecs::JSON,
  :processors         => [],
  :reporters          => [],
  :metrics            => nil,
  :delay              => true,
  :delay_options      => DELAY_PROCESSOR_DEFAULTS,
  :pidfile            => nil,
  :require            => '.'
}.freeze

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

processor example

:processor          => Processor,
:connection_options => {,
:workers            => [],
:concurrency        => 1,
:ack                => true,
:handler_class      => nil,
:handler_options    => nil,
:codec              => PikaQue::Codecs::JSON

}



78
79
80
# File 'lib/pika_que/configuration.rb', line 78

def initialize
  @config = DEFAULT_CONFIG.dup
end

Instance Method Details

#add_processor(opts = {}) ⇒ Object



105
106
107
# File 'lib/pika_que/configuration.rb', line 105

def add_processor(opts = {})
  @config[:processors] << processor(opts)
end

#deep_merge(first, second) ⇒ Object



93
94
95
96
# File 'lib/pika_que/configuration.rb', line 93

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

#merge(other = {}) ⇒ Object



86
87
88
89
90
91
# File 'lib/pika_que/configuration.rb', line 86

def merge(other = {})
  instance = self.class.new
  instance.merge! to_hash
  instance.merge! other
  instance
end

#merge!(other = {}) ⇒ Object



82
83
84
# File 'lib/pika_que/configuration.rb', line 82

def merge!(other = {})
  @config = deep_merge(@config, other)
end

#processor(opts = {}) ⇒ Object



98
99
100
101
102
103
# File 'lib/pika_que/configuration.rb', line 98

def processor(opts = {})
  {
    :processor        => PikaQue::Processor,
    :workers          => []
  }.merge(opts)
end