Module: Carnivore

Defined in:
lib/carnivore.rb,
lib/carnivore/utils.rb,
lib/carnivore/source.rb,
lib/carnivore/config.rb,
lib/carnivore/errors.rb,
lib/carnivore/runner.rb,
lib/carnivore/version.rb,
lib/carnivore/message.rb,
lib/carnivore/callback.rb,
lib/carnivore/container.rb,
lib/carnivore/supervisor.rb,
lib/carnivore/utils/smash.rb,
lib/carnivore/spec_helper.rb,
lib/carnivore/source/test.rb,
lib/carnivore/utils/params.rb,
lib/carnivore/utils/logging.rb,
lib/carnivore/source_container.rb,
lib/carnivore/utils/message_registry.rb

Overview

Message consumer and processor

Defined Under Namespace

Modules: Utils Classes: Callback, Config, Container, Error, Message, Source, Supervisor, Version

Constant Summary

VERSION =

Current version of library

Version.new('0.2.2')

Class Method Summary (collapse)

Class Method Details

+ (self) configure { ... }

Add configuration to Carnivore

Yields:

  • block of configuration

Returns:

  • (self)


10
11
12
13
14
# File 'lib/carnivore/runner.rb', line 10

def configure(&block)
  mod = Container.new
  mod.instance_exec(mod, &block)
  self
end

+ (Object) start!

Start the Carnivore subsystem



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/carnivore/runner.rb', line 17

def start!
  supervisor = nil
  begin
    require 'carnivore/supervisor'
    supervisor = Carnivore::Supervisor.build!
    Source.sources.each do |source|
      source.klass.reset_comms!
      supervisor.supervise_as(
        source.source_hash[:name],
        source.klass,
        source.source_hash.dup
      )
    end
    loop do
      # We do a sleep loop so we can periodically check on the
      # supervisor and ensure it is still alive. If it has died,
      # raise exception to allow cleanup and restart attempt
      sleep Carnivore::Config.get(:carnivore, :supervisor, :poll) || 5 while supervisor.alive?
      Celluloid::Logger.error 'Carnivore supervisor has died!'
      raise Carnivore::Error::DeadSupervisor.new
    end
  rescue Carnivore::Error::DeadSupervisor
    Celluloid::Logger.warn "Received dead supervisor exception. Attempting to restart."
    begin
      supervisor.terminate
    rescue => e
      Celluloid::Logger.debug "Exception raised during supervisor termination (restart cleanup): #{e}"
    end
    Celluloid::Logger.debug "Pausing restart for 10 seconds to prevent restart thrashing cycles"
    sleep 10
    retry
  rescue Exception => e
    Celluloid::Logger.warn "Exception type encountered forcing shutdown - #{e.class}: #{e}"
    Celluloid::Logger.debug "Shutdown exception info: #{e.class}: #{e}\n#{e.backtrace.join("\n")}"
    supervisor.terminate if supervisor
    # Gracefully shut down
  end
end