Module: MotherBrain::Application
- Extended by:
- Forwardable, MB::Mixin::Services, Logging
- Defined in:
- lib/mb/application.rb
Overview
Main application supervisor for motherbrain
Defined Under Namespace
Classes: SupervisionGroup
Class Method Summary collapse
- .instance ⇒ Celluloid::SupervisionGroup(MB::Application::SupervisionGroup)
-
.registry ⇒ Celluloid::Registry
The Actor registry for motherbrain.
-
.run(config) ⇒ Object
Run the application in the foreground (sleep on main thread).
-
.run!(config) ⇒ Object
Run the application asynchronously (terminate after execution).
-
.setup ⇒ Object
Prepare the application and environment to run motherbrain.
-
.stop ⇒ Object
Stop the running application.
Methods included from Logging
add_argument_header, dev, filename, log_exception, logger, logger, reset, set_logger
Class Method Details
.instance ⇒ Celluloid::SupervisionGroup(MB::Application::SupervisionGroup)
44 45 46 47 48 |
# File 'lib/mb/application.rb', line 44 def instance return @instance unless @instance.nil? raise Celluloid::DeadActorError, "application not running" end |
.registry ⇒ Celluloid::Registry
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[].
The Actor registry for motherbrain.
57 58 59 |
# File 'lib/mb/application.rb', line 57 def registry @registry ||= Celluloid::Registry.new end |
.run(config) ⇒ Object
Run the application in the foreground (sleep on main thread)
74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/mb/application.rb', line 74 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!(config) ⇒ Object
Run the application asynchronously (terminate after execution)
64 65 66 67 68 69 |
# File 'lib/mb/application.rb', line 64 def run!(config) Celluloid.boot log.info { "motherbrain starting..." } setup @instance = Application::SupervisionGroup.new(config) end |
.setup ⇒ Object
Prepare the application and environment to run motherbrain
87 88 89 90 |
# File 'lib/mb/application.rb', line 87 def setup MB::Test.mock(:setup) if MB.testing? MB::FileSystem.init end |
.stop ⇒ Object
Stop the running application
93 94 95 |
# File 'lib/mb/application.rb', line 93 def stop instance.terminate end |