Class: Async::Container::Policy

Inherits:
Object
  • Object
show all
Defined in:
lib/async/container/policy.rb

Overview

A policy for managing container behavior and responding to child process lifecycle events.

Constant Summary collapse

DEFAULT =

The default policy instance.

self.new.freeze

Instance Method Summary collapse

Instance Method Details

#abort?(status) ⇒ Boolean

Helper method to check if a status indicates an abort.

Returns:

  • (Boolean)


63
64
65
# File 'lib/async/container/policy.rb', line 63

def abort?(status)
	status&.termsig == Signal.list["ABRT"]
end

#child_exit(container, child, status, name:, key:, **options) ⇒ Object

Called when a child exits.



26
27
# File 'lib/async/container/policy.rb', line 26

def child_exit(container, child, status, name:, key:, **options)
end

#child_spawn(container, child, name:, key:, **options) ⇒ Object

Called when a child is spawned.



16
17
# File 'lib/async/container/policy.rb', line 16

def child_spawn(container, child, name:, key:, **options)
end

#exit_code(status) ⇒ Object

Helper method to get the exit code.



91
92
93
# File 'lib/async/container/policy.rb', line 91

def exit_code(status)
	status&.exitstatus
end

#health_check_failed(container, child, age:, timeout:, **options) ⇒ Object

Called when a health check fails. Subclasses can override to implement custom behavior (e.g., alerting before killing).



36
37
38
39
# File 'lib/async/container/policy.rb', line 36

def health_check_failed(container, child, age:, timeout:, **options)
	Console.warn(self, "Health check failed!", child: child, age: age, timeout: timeout)
	child.kill!
end

#killed?(status) ⇒ Boolean

Helper method to check if a status indicates the process was killed.

Returns:

  • (Boolean)


70
71
72
# File 'lib/async/container/policy.rb', line 70

def killed?(status)
	status&.termsig == Signal.list["KILL"]
end

#make_statisticsObject

Create statistics for a container. Can be overridden by subclasses to customize the statistics window.



98
99
100
# File 'lib/async/container/policy.rb', line 98

def make_statistics
	Statistics.new
end

#segfault?(status) ⇒ Boolean

Helper method to check if a status indicates a segfault.

Returns:

  • (Boolean)


56
57
58
# File 'lib/async/container/policy.rb', line 56

def segfault?(status)
	status&.termsig == Signal.list["SEGV"]
end

#signal(status) ⇒ Object

Helper method to get the signal that terminated the process.



84
85
86
# File 'lib/async/container/policy.rb', line 84

def signal(status)
	status&.termsig
end

#startup_failed(container, child, age:, timeout:, **options) ⇒ Object

Called when startup fails (child doesn’t become ready in time). Subclasses can override to implement custom behavior (e.g., alerting before killing).



48
49
50
51
# File 'lib/async/container/policy.rb', line 48

def startup_failed(container, child, age:, timeout:, **options)
	Console.warn(self, "Startup failed!", child: child, age: age, timeout: timeout)
	child.kill!
end

#success?(status) ⇒ Boolean

Helper method to check if a status indicates success.

Returns:

  • (Boolean)


77
78
79
# File 'lib/async/container/policy.rb', line 77

def success?(status)
	status&.success?
end