Ravn::

ActorRunner module

Constants

HANDLED_SIGNALS

Signals to trap

Public Class Methods

extended( mod )

Extension callback – add some instance variables.

# File lib/ravn/actor_runner.rb, line 20
def self::extended( mod )
        super

        mod.extend( Sysexits )
        mod.extend( Ravn::SignalHandling )
        unless mod.respond_to?( :log )
                mod.extend( Loggability )
                mod.log_to( :ravn )
        end

        mod.instance_variable_set( :@toplevel_actor, nil )
        mod.instance_variable_set( :@exitcode, nil )
        mod.singleton_class.attr_reader :toplevel_actor
        mod.singleton_class.attr_accessor :exitcode
end

Public Instance Methods

handle_HUP()

Handle a HUP signal

# File lib/ravn/actor_runner.rb, line 108
def handle_HUP
        self.reload
end
handle_INFO()

Handle a INFO signal

# File lib/ravn/actor_runner.rb, line 114
def handle_INFO
        self.show_actor_tree
end
handle_INT()

Handle a INT signal

# File lib/ravn/actor_runner.rb, line 90
def handle_INT
        self.shutdown
end
handle_QUIT()

Handle a QUIT signal

# File lib/ravn/actor_runner.rb, line 102
def handle_QUIT
        self.shutdown
end
handle_TERM()

Handle a TERM signal

# File lib/ravn/actor_runner.rb, line 96
def handle_TERM
        self.shutdown
end
handle_signal( sig )

Handle signals.

# File lib/ravn/actor_runner.rb, line 120
def handle_signal( sig )
        handler = "handle_%s" % [ sig.to_s ]

        if self.respond_to?( handler )
                self.log.warn "Handling signal %p" % [ sig ]
                self.send( handler )
        else
                self.log.warn "Unhandled signal %s" % [ sig ]
        end
end
reload()

Reload the config and restart the BDE.

# File lib/ravn/actor_runner.rb, line 75
def reload
        self.toplevel_actor.ask!( :pause! )
        Ravn.config.reload
        self.toplevel_actor.tell( :resume! )
end
run( *args, **options )

Start the top-level actor and loop until either it or the signal handler terminates.

# File lib/ravn/actor_runner.rb, line 39
def run( *args, **options )
        self.with_signal_handler( *HANDLED_SIGNALS ) do
                @toplevel_actor = self.spawn_toplevel_actor( *args, **options )

                while !@toplevel_actor.ask!( :terminated? ) && self.handling_signals?
                        sleep( Ravn::SignalHandling::IDLE_CHECK_INTERVAL )
                end
        end

        self.log.warn "Exiting ActorRunner run loop."
        exit self.exitcode || :success
rescue => err
        trace = err.full_message( highlight: $stderr.isatty, order: :bottom )
        self.log.error "Halting: uncaught %p: %s" % [ err.class, trace ]

        exit :software
end
show_actor_tree()

Dump the actor tree to STDERR.

# File lib/ravn/actor_runner.rb, line 83
def show_actor_tree
        tree = self.toplevel_actor.ask!( dump_tree: nil )
        $stderr.puts( tree.render )
end
shutdown()

Shut down the BDE

# File lib/ravn/actor_runner.rb, line 66
def shutdown
        self.log.warn "Shutting down top-level actor: %p." % [ self.toplevel_actor ]
        self.toplevel_actor.ask!( :terminate! )
        self.log.warn "Controller is done."
        self.stop_signal_handler
end
spawn_toplevel_actor( * )

Spawn the top-most actor (a Concurrent::Actor) and return its Reference. Must be implemented by the extended object.

# File lib/ravn/actor_runner.rb, line 60
def spawn_toplevel_actor( * )
        raise NotImplementedError, "%s does not implement required method %s" % [ self, __method__ ]
end