Class: Lepus::Supervisor

Inherits:
Processes::Base show all
Includes:
ChildrenPipes, LifecycleHooks, Maintenance, Pidfiled, RegistryCleaner, Signals
Defined in:
lib/lepus/supervisor.rb,
lib/lepus/supervisor/pidfile.rb,
lib/lepus/supervisor/signals.rb,
lib/lepus/supervisor/pidfiled.rb,
lib/lepus/supervisor/maintenance.rb,
lib/lepus/supervisor/children_pipes.rb,
lib/lepus/supervisor/lifecycle_hooks.rb,
lib/lepus/supervisor/registry_cleaner.rb

Defined Under Namespace

Modules: ChildrenPipes, LifecycleHooks, Maintenance, Pidfiled, RegistryCleaner, Signals Classes: Pidfile

Constant Summary collapse

SHUTDOWN_MSG =
"shutdown"

Instance Attribute Summary

Attributes inherited from Processes::Base

#name

Class Method Summary collapse

Instance Method Summary collapse

Methods included from RegistryCleaner

included

Methods included from Pidfiled

included

Methods included from Signals

included

Methods included from Maintenance

included

Methods included from ChildrenPipes

included

Methods included from LifecycleHooks

included

Methods inherited from Processes::Base

#hostname, #kind, #metadata, #pid

Methods included from Processes::Procline

#procline

Methods included from Processes::Interruptible

#interrupt

Methods included from Processes::Registrable

included

Methods included from AppExecutor

#handle_thread_error, #wrap_in_app_executor

Methods included from Processes::Callbacks

included

Constructor Details

#initialize(require_file: nil, pidfile: "tmp/pids/lepus.pid", shutdown_timeout: 5, **kwargs) ⇒ Supervisor

Returns a new instance of Supervisor.

Parameters:

  • require_file (String, nil) (defaults to: nil)

    The file to require before loading consumers, typically the Rails environment file or similar.

  • pidfile (String) (defaults to: "tmp/pids/lepus.pid")

    The path to the pidfile where the supervisor’s PID will be stored. Default is “tmp/pids/lepus.pid”.

  • shutdown_timeout (Integer) (defaults to: 5)

    The timeout in seconds to wait for child processes to terminate gracefully before forcing termination. Default is 5 seconds.

  • consumers (Array<String, Class>)

    An optional list of consumer class names (as strings or constants) to be run by this supervisor. If not provided, all discovered consumer classes will be used.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/lepus/supervisor.rb', line 24

def initialize(require_file: nil, pidfile: "tmp/pids/lepus.pid", shutdown_timeout: 5, **kwargs)
  @pidfile_path = pidfile
  @require_file = require_file
  @shutdown_timeout = shutdown_timeout.to_i
  @consumer_class_names = Array(kwargs[:consumers]).map(&:to_s) if kwargs.key?(:consumers)

  @forks = {}
  @pipes = {}
  @configured_processes = {}

  super

  @name ||= hostname
end

Class Method Details

.start(**options) ⇒ Object



15
16
17
# File 'lib/lepus/supervisor.rb', line 15

def start(**options)
  new(**options).tap(&:start)
end

Instance Method Details

#startObject



39
40
41
42
43
44
45
46
47
48
# File 'lib/lepus/supervisor.rb', line 39

def start
  boot

  run_start_hooks

  build_and_start_workers
  launch_maintenance_task

  supervise
end

#stopObject



50
51
52
53
54
# File 'lib/lepus/supervisor.rb', line 50

def stop
  super

  run_stop_hooks
end