Class: DaemonKit::Nanite::Agent

Inherits:
Object
  • Object
show all
Defined in:
lib/daemon_kit/nanite/agent.rb

Overview

Pull support into a daemon for being a nanite agent.

Constant Summary collapse

@@instance =
nil

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAgent

Returns a new instance of Agent.



43
44
45
46
47
# File 'lib/daemon_kit/nanite/agent.rb', line 43

def initialize
  @config = DaemonKit::Config.load( 'nanite' ).to_h( true )

  config_agent
end

Class Method Details

.instanceObject



31
32
33
# File 'lib/daemon_kit/nanite/agent.rb', line 31

def instance
  @instance ||= new
end

.run(&block) ⇒ Object



37
38
39
# File 'lib/daemon_kit/nanite/agent.rb', line 37

def run(&block)
  instance.run(&block)
end

Instance Method Details

#run(&block) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/daemon_kit/nanite/agent.rb', line 49

def run(&block)
  # Ensure graceful shutdown of the connection to the broker
  DaemonKit.trap('INT') { ::EM.stop }
  DaemonKit.trap('TERM') { ::EM.stop }
  ::Nanite::Log.logger = DaemonKit.logger

  # Start our mapper
  mapper_thread = Thread.new do
    EM.run do
      agent = ::Nanite::Agent.new( @config )
      agent.init_block = block
      agent.run
    end
  end

  mapper_thread.join
end