Life Cycle Events - lifechurch/subserver GitHub Wiki
Subserver has several events triggered throughout its lifecycle that can be hooked into.
Hooks are inserted into the life cycle events using the subserver.rb configuration initializer.
/config/initializers/subserver.rb
Subserver.configure do |config|
config.on(:startup) do
# Add block to run at startup
end
end
config.on
can be ran multiple times to insert as many blocks to run at that life cycle as desired.
Startup
The Startup event is triggered after all startup validations have ran before any listeners are started. At this point Subserver is still in the main thread and has not yet forked to start the heath server or any listeners.
Hooks for the startup event are ran in order.
Listener Startup
This event is fired each time a listener is started. This can be used to run code that needs to be ran after threads have been forked.
This hook is commonly used to setup Pub/Sub topics if your Subscribers also publish to a topic. This is due to the fact that the underlying GRPC connection in Google Pub/Sub Ruby cannot be forked so it must be created after any new thread is started.
Hooks for the listener startup event are ran in order.
Quiet
This event is fired when Subserver is told to gracefully shutdown its listeners giving them time to finish executing.
Hooks for the quiet event are ran in reverse order so that you can "backout" of the system.
Shutdown
This event is fired just before the Subserver is terminated either due to a timeout after a quiet or due to receiving SIGTERM.
Hooks for the shutdown event are ran in reverse order so that you can "backout" of the system.