class Policy
A policy for managing container behavior and responding to child process lifecycle events.
Definitions
def child_spawn(container, child, name:, key:, **options)
Called when a child is spawned.
Signature
-
parameter
containerGeneric The container.
-
parameter
childChild The child process.
-
parameter
nameString The name of the child.
-
parameter
keySymbol An optional key for the child.
-
parameter
optionsHash Additional options for future extensibility.
Implementation
def child_spawn(container, child, name:, key:, **options)
end
def child_exit(container, child, status, name:, key:, **options)
Called when a child exits.
Signature
-
parameter
containerGeneric The container.
-
parameter
childChild The child process.
-
parameter
statusProcess::Status The exit status.
-
parameter
nameString The name of the child.
-
parameter
keySymbol An optional key for the child.
-
parameter
optionsHash Additional options for future extensibility.
Implementation
def child_exit(container, child, status, name:, key:, **options)
end
def health_check_failed(container, child, age:, timeout:, **options)
Called when a health check fails. Subclasses can override to implement custom behavior (e.g., alerting before killing).
Signature
-
parameter
containerGeneric The container.
-
parameter
childChild The child process.
-
parameter
ageNumeric How long the child has been running.
-
parameter
timeoutNumeric The health check timeout that was exceeded.
-
parameter
optionsHash Additional options for future extensibility.
Implementation
def health_check_failed(container, child, age:, timeout:, **options)
Console.warn(self, "Health check failed!", child: child, age: age, timeout: timeout)
child.kill!
end
def startup_failed(container, child, age:, timeout:, **options)
Called when startup fails (child doesn't become ready in time). Subclasses can override to implement custom behavior (e.g., alerting before killing).
Signature
-
parameter
containerGeneric The container.
-
parameter
childChild The child process.
-
parameter
ageNumeric How long the child has been running.
-
parameter
timeoutNumeric The startup timeout that was exceeded.
-
parameter
optionsHash Additional options for future extensibility.
Implementation
def startup_failed(container, child, age:, timeout:, **options)
Console.warn(self, "Startup failed!", child: child, age: age, timeout: timeout)
child.kill!
end
def segfault?(status)
Helper method to check if a status indicates a segfault.
Signature
-
parameter
statusProcess::Status The exit status.
-
returns
Boolean Whether the process was terminated by SIGSEGV.
Implementation
def segfault?(status)
status&.termsig == Signal.list["SEGV"]
end
def abort?(status)
Helper method to check if a status indicates an abort.
Signature
-
parameter
statusProcess::Status The exit status.
-
returns
Boolean Whether the process was terminated by SIGABRT.
Implementation
def abort?(status)
status&.termsig == Signal.list["ABRT"]
end
def killed?(status)
Helper method to check if a status indicates the process was killed.
Signature
-
parameter
statusProcess::Status The exit status.
-
returns
Boolean Whether the process was terminated by SIGKILL.
Implementation
def killed?(status)
status&.termsig == Signal.list["KILL"]
end
def success?(status)
Helper method to check if a status indicates success.
Signature
-
parameter
statusProcess::Status The exit status.
-
returns
Boolean Whether the process exited successfully.
Implementation
def success?(status)
status&.success?
end
def signal(status)
Helper method to get the signal that terminated the process.
Signature
-
parameter
statusProcess::Status The exit status.
-
returns
Integer, nil The signal number, or nil if not terminated by signal.
Implementation
def signal(status)
status&.termsig
end
def exit_code(status)
Helper method to get the exit code.
Signature
-
parameter
statusProcess::Status The exit status.
-
returns
Integer, nil The exit code, or nil if terminated by signal.
Implementation
def exit_code(status)
status&.exitstatus
end
DEFAULT = self.new.freeze
The default policy instance.