module RocketJob::Supervisor::Shutdown

Public Class Methods

event!() click to toggle source

An event has occured

# File lib/rocket_job/supervisor/shutdown.rb, line 22
def self.event!
  @event.set
end
shutdown!() click to toggle source

Set shutdown indicator for this server process

# File lib/rocket_job/supervisor/shutdown.rb, line 11
def self.shutdown!
  @shutdown.set
  event!
end
shutdown?() click to toggle source

Returns [true|false] whether the shutdown indicator has been set for this server process

# File lib/rocket_job/supervisor/shutdown.rb, line 17
def self.shutdown?
  @shutdown.set?
end
wait_for_event(timeout = nil) click to toggle source

Returns [true|false] whether the shutdown indicator was set before the timeout was reached

# File lib/rocket_job/supervisor/shutdown.rb, line 27
def self.wait_for_event(timeout = nil)
  @event.wait(timeout)
  @event.reset
end

Private Class Methods

register_signal_handlers() click to toggle source

Register handlers for the various signals Term:

Perform clean shutdown
# File lib/rocket_job/supervisor/shutdown.rb, line 39
def self.register_signal_handlers
  Signal.trap "SIGTERM" do
    Thread.new do
      shutdown!
      message = "Shutdown signal (SIGTERM) received. Will shutdown as soon as active jobs/slices have completed."
      logger.info(message)
    end
  end

  Signal.trap "INT" do
    Thread.new do
      shutdown!
      message = "Shutdown signal (INT) received. Will shutdown as soon as active jobs/slices have completed."
      logger.info(message)
    end
  end
rescue StandardError
  logger.warn "SIGTERM handler not installed. Not able to shutdown gracefully"
end