Class: Pgbus::Process::Supervisor
- Inherits:
-
Object
- Object
- Pgbus::Process::Supervisor
- Includes:
- SignalHandler
- Defined in:
- lib/pgbus/process/supervisor.rb
Constant Summary collapse
- FORK_WAIT =
seconds between fork checks
1
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #graceful_shutdown ⇒ Object
- #immediate_shutdown ⇒ Object
-
#initialize(config: Pgbus.configuration) ⇒ Supervisor
constructor
A new instance of Supervisor.
- #run ⇒ Object
Methods included from SignalHandler
included, #interruptible_sleep, #process_signals, #restore_signals, #setup_signals
Constructor Details
#initialize(config: Pgbus.configuration) ⇒ Supervisor
Returns a new instance of Supervisor.
12 13 14 15 16 |
# File 'lib/pgbus/process/supervisor.rb', line 12 def initialize(config: Pgbus.configuration) @config = config @forks = {} @shutting_down = false end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
10 11 12 |
# File 'lib/pgbus/process/supervisor.rb', line 10 def config @config end |
Instance Method Details
#graceful_shutdown ⇒ Object
38 39 40 41 42 |
# File 'lib/pgbus/process/supervisor.rb', line 38 def graceful_shutdown Pgbus.logger.info { "[Pgbus] Supervisor: graceful shutdown requested" } @shutting_down = true signal_children("TERM") end |
#immediate_shutdown ⇒ Object
44 45 46 47 48 |
# File 'lib/pgbus/process/supervisor.rb', line 44 def immediate_shutdown Pgbus.logger.warn { "[Pgbus] Supervisor: immediate shutdown requested" } @shutting_down = true signal_children("QUIT") end |
#run ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/pgbus/process/supervisor.rb', line 18 def run setup_signals start_heartbeat Pgbus.logger.info { "[Pgbus] Supervisor starting pid=#{::Process.pid}" } # Bootstrap queues once in the parent process before forking children. # This avoids the deadlock that occurs when multiple forked children # race to call enable_notify_insert (DROP TRIGGER + CREATE TRIGGER) # concurrently on the same queue tables. Children still call # bootstrap_queues post-fork but the idempotent check in # notify_trigger_current? makes those calls cheap no-ops. bootstrap_queues boot_processes monitor_loop ensure shutdown end |