Async::ContainerSourceAsyncContainerPolicy

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 container Generic

The container.

parameter child Child

The child process.

parameter name String

The name of the child.

parameter key Symbol

An optional key for the child.

parameter options Hash

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 container Generic

The container.

parameter child Child

The child process.

parameter status Process::Status

The exit status.

parameter name String

The name of the child.

parameter key Symbol

An optional key for the child.

parameter options Hash

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 container Generic

The container.

parameter child Child

The child process.

parameter age Numeric

How long the child has been running.

parameter timeout Numeric

The health check timeout that was exceeded.

parameter options Hash

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 container Generic

The container.

parameter child Child

The child process.

parameter age Numeric

How long the child has been running.

parameter timeout Numeric

The startup timeout that was exceeded.

parameter options Hash

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 status Process::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 status Process::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 status Process::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 status Process::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 status Process::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 status Process::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.