lib/async/container/controller.rb in async-container-0.16.13 vs lib/async/container/controller.rb in async-container-0.17.0

- old
+ new

@@ -20,12 +20,13 @@ SIGUSR1 = Signal.list["USR1"] SIGUSR2 = Signal.list["USR2"] # Initialize the controller. # @parameter notify [Notify::Client] A client used for process readiness notifications. - def initialize(notify: Notify.open!) + def initialize(notify: Notify.open!, container_class: Container) @container = nil + @container_class = container_class if @notify = notify @notify.status!("Initializing...") end @@ -64,11 +65,11 @@ # Create a container for the controller. # Can be overridden by a sub-class. # @returns [Generic] A specific container instance to use. def create_container - Container.new + @container_class.new end # Whether the controller has a running container. # @returns [Boolean] def running? @@ -99,10 +100,11 @@ @container&.stop(graceful) @container = nil end # Restart the container. A new container is created, and if successful, any old container is terminated gracefully. + # This is equivalent to a blue-green deployment. def restart if @container @notify&.restarting! Console.logger.debug(self) {"Restarting container..."} @@ -112,23 +114,23 @@ container = self.create_container begin self.setup(container) - rescue - @notify&.error!($!.to_s) + rescue => error + @notify&.error!(error.to_s) raise SetupError, container end # Wait for all child processes to enter the ready state. Console.logger.debug(self, "Waiting for startup...") container.wait_until_ready Console.logger.debug(self, "Finished startup.") if container.failed? - @notify&.error!($!.to_s) + @notify&.error!("Container failed to start!") container.stop raise SetupError, container end @@ -163,10 +165,10 @@ Console.logger.debug(self, "Waiting for startup...") @container.wait_until_ready Console.logger.debug(self, "Finished startup.") if @container.failed? - @notify.error!("Container failed!") + @notify.error!("Container failed to reload!") raise SetupError, @container else @notify&.ready! end