module MotherBrain::Application
Main application supervisor for motherbrain
@example running the application in the foreground
MB::Application.run(config)
@example running the application in the background
MB::Application.run!(config)
Public Class Methods
@raise [Celluloid::DeadActorError] if Application
has not been started
@return [Celluloid::SupervisionGroup(MB::Application::SupervisionGroup)]
# File lib/mb/application.rb, line 50 def instance return @instance unless @instance.nil? raise Celluloid::DeadActorError, "application not running" end
Set the application state to paused. This allows actors to continue processing, but causes the RestGateway
not to accept new requests.
See: MotherBrain::API::V1
L51, ‘before’ block
# File lib/mb/application.rb, line 113 def pause @status = Status::PAUSED end
# File lib/mb/application.rb, line 121 def paused? status == Status::PAUSED end
The Actor registry for motherbrain.
@note motherbrain uses it’s own registry instead of Celluloid::Registry.root to
avoid conflicts in the larger namespace. Use MB::Application[] to access motherbrain actors instead of Celluloid::Actor[].
@return [Celluloid::Registry]
# File lib/mb/application.rb, line 63 def registry @registry ||= Celluloid::Registry.new end
# File lib/mb/application.rb, line 117 def resume @status = Status::RUNNING end
Run the application in the foreground (sleep on main thread)
@param [MB::Config] config
# File lib/mb/application.rb, line 84 def run(config) loop do supervisor = run!(config) sleep 0.1 while supervisor.alive? break if supervisor.interrupted log.fatal { "!!! #{self} crashed. Restarting..." } end end
Run the application asynchronously (terminate after execution)
@param [MB::Config] config
# File lib/mb/application.rb, line 70 def run!(config) Celluloid.boot Celluloid.exception_handler do |ex| log.fatal { "Application received unhandled exception: #{ex.class} - #{ex.message}" } log.fatal { ex.backtrace.join("\n\t") } end log.info { "motherbrain starting..." } setup @instance = Application::SupervisionGroup.new(config) end
Prepare the application and environment to run motherbrain
# File lib/mb/application.rb, line 97 def setup MB::Test.mock(:setup) if MB.testing? MB::FileSystem.init end
# File lib/mb/application.rb, line 125 def status @status ||= Status::RUNNING end
Stop the running application
# File lib/mb/application.rb, line 103 def stop instance.async_interrupt(3) @status = Status::STOPPING end