lib/mb/application.rb in motherbrain-1.3.0 vs lib/mb/application.rb in motherbrain-1.4.0

- old
+ new

@@ -26,10 +26,16 @@ # MB::Application.run(config) # # @example running the application in the background # MB::Application.run!(config) module Application + module Status + RUNNING = :running + PAUSED = :paused + STOPPING = :stopping + end + class << self extend Forwardable include MB::Mixin::Services include MB::Logging @@ -93,12 +99,34 @@ MB::FileSystem.init end # Stop the running application def stop - instance.terminate + instance.async_interrupt(3) + @status = Status::STOPPING 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 + def pause + @status = Status::PAUSED + end + + def resume + @status = Status::RUNNING + end + + def paused? + status == Status::PAUSED + end + + def status + @status ||= Status::RUNNING + end end class SupervisionGroup < ::Celluloid::SupervisionGroup include Celluloid::Notifications include MB::Logging @@ -133,10 +161,15 @@ def reconfigure(_msg, new_config) log.debug { "[Application] ConfigManager has changed: re-configuring components..." } @registry[:ridley].async.configure(new_config.to_ridley) end - def interrupt + def async_interrupt(delay = 0) + future.interrupt(delay) + end + + def interrupt(delay = 0) + Celluloid.sleep(delay) if delay > 0 interrupt_mutex.synchronize do unless interrupted @interrupted = true terminate end