Sha256: 6dcb4ab424f765d32558c83d5343dbae7a8cda2e0fb4abac52fc1a2f9f9f0986
Contents?: true
Size: 1.14 KB
Versions: 29
Compression:
Stored size: 1.14 KB
Contents
module DaemonKit module Nanite # Pull support into a daemon for being a nanite agent. class Agent @@instance = nil class << self def instance @instance ||= new end private :new def run(&block) instance.run(&block) end end def initialize @config = DaemonKit::Config.load( 'nanite' ).to_h( true ) config_agent end 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 ) block.call( agent ) if block end end #block.call if block mapper_thread.join end private # Make sure to fine tune the agent config to be DK friendly def config_agent @config[:root] = DAEMON_ROOT @config[:daemonize] = false @config[:actors_dir] = File.join(DAEMON_ROOT, 'lib', 'actors') end end end end
Version data entries
29 entries across 29 versions & 5 rubygems