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.



22
23
24
25
26
# File 'lib/daemon_kit/nanite/agent.rb', line 22

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

  config_agent
end

Class Method Details

.instanceObject



10
11
12
# File 'lib/daemon_kit/nanite/agent.rb', line 10

def instance
  @instance ||= new
end

.run(&block) ⇒ Object



16
17
18
# File 'lib/daemon_kit/nanite/agent.rb', line 16

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

Instance Method Details

#run(&block) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/daemon_kit/nanite/agent.rb', line 28

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

  # Start our mapper
  mapper_thread = Thread.new do
    EM.run do
      agent = ::Nanite.start_agent( @config.to_h( true ) )
      block.call( agent ) if block
    end
  end

  #block.call if block

  mapper_thread.join
end