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
Modules: Status Classes: SupervisionGroup
Class Method Summary collapse
- .instance ⇒ Celluloid::SupervisionGroup(MB::Application::SupervisionGroup)
-
.pause ⇒ Object
Set the application state to paused.
- .paused? ⇒ Boolean
-
.registry ⇒ Celluloid::Registry
The Actor registry for motherbrain.
- .resume ⇒ Object
-
.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.
- .status ⇒ Object
-
.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)
50 51 52 53 54 |
# File 'lib/mb/application.rb', line 50 def instance return @instance unless @instance.nil? raise Celluloid::DeadActorError, "application not running" end |
.pause ⇒ Object
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
113 114 115 |
# File 'lib/mb/application.rb', line 113 def pause @status = Status::PAUSED end |
.paused? ⇒ Boolean
121 122 123 |
# File 'lib/mb/application.rb', line 121 def paused? status == Status::PAUSED 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.
63 64 65 |
# File 'lib/mb/application.rb', line 63 def registry @registry ||= Celluloid::Registry.new end |
.resume ⇒ Object
117 118 119 |
# File 'lib/mb/application.rb', line 117 def resume @status = Status::RUNNING end |
.run(config) ⇒ Object
Run the application in the foreground (sleep on main thread)
84 85 86 87 88 89 90 91 92 93 94 |
# 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!(config) ⇒ Object
Run the application asynchronously (terminate after execution)
70 71 72 73 74 75 76 77 78 79 |
# 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.}" } log.fatal { ex.backtrace.join("\n\t") } end log.info { "motherbrain starting..." } setup @instance = Application::SupervisionGroup.new(config) end |
.setup ⇒ Object
Prepare the application and environment to run motherbrain
97 98 99 100 |
# File 'lib/mb/application.rb', line 97 def setup MB::Test.mock(:setup) if MB.testing? MB::FileSystem.init end |