Module: Lich::Main::UserExitDispatch
- Defined in:
- documented/main/user_exit_dispatch.rb
Overview
User-initiated ("...exit"/"...quit") shutdown entry point shared by the
primary and detachable frontend client loops in lib/main/main.rb.
Extracted from main.rb so the ordering guarantee it enforces is directly
testable: the shutdown watchdog must be armed before
Common::OrderlyShutdown.request_user_exit runs, because that call
drains scripts and runs their +before_dying+/+at_exit+ hooks inline, any of
which can hang. A bare request_user_exit would run that hang-prone drain
unprotected.
Class Method Summary collapse
-
.active_sessions_lifecycle ⇒ Object?
Resolves the ActiveSessions lifecycle when the feature is loaded, so a normal exit updates the session registry; nil otherwise.
-
.dispatch_detachable_client(client_string, cmd_prefix: $cmd_prefix, **request_options) ⇒ Boolean
Detachable-frontend dispatch for one raw client line.
-
.run_orderly_user_shutdown(source: :primary_frontend, **request_options) ⇒ Object
Arms the shutdown watchdog (idempotent) and then runs the orderly user-exit sequence.
Class Method Details
.active_sessions_lifecycle ⇒ Object?
Resolves the ActiveSessions lifecycle when the feature is loaded, so a normal exit updates the session registry; nil otherwise.
70 71 72 |
# File 'documented/main/user_exit_dispatch.rb', line 70 def active_sessions_lifecycle Lich::InternalAPI::ActiveSessions::Lifecycle if defined?(Lich::InternalAPI::ActiveSessions::Lifecycle) end |
.dispatch_detachable_client(client_string, cmd_prefix: $cmd_prefix, **request_options) ⇒ Boolean
Detachable-frontend dispatch for one raw client line.
Applies the same $cmd_prefix prefixing the client loops use before
matching, and when the (prefixed) line is a user-exit command, arms the
watchdog and runs the orderly shutdown under the :detachable_frontend
source. The caller breaks its read loop when this returns true.
54 55 56 57 58 59 60 61 62 63 64 |
# File 'documented/main/user_exit_dispatch.rb', line 54 def dispatch_detachable_client(client_string, cmd_prefix: $cmd_prefix, **) prefixed = "#{cmd_prefix}#{client_string}" return false unless Lich::Common::ShutdownIntent.user_exit_command?(prefixed) run_orderly_user_shutdown( source: :detachable_frontend, **, server_exit_command: prefixed ) true end |
.run_orderly_user_shutdown(source: :primary_frontend, **request_options) ⇒ Object
Arms the shutdown watchdog (idempotent) and then runs the orderly
user-exit sequence. Extra keyword options are forwarded to
Common::OrderlyShutdown.request_user_exit (used by tests to inject
the script drain, Vars, and Game collaborators).
34 35 36 37 38 39 40 41 |
# File 'documented/main/user_exit_dispatch.rb', line 34 def run_orderly_user_shutdown(source: :primary_frontend, **) Lich::Common::ShutdownWatchdog.arm if defined?(Lich::Common::ShutdownWatchdog) Lich::Common::OrderlyShutdown.request_user_exit( source: source, active_sessions_lifecycle: active_sessions_lifecycle, ** ) end |