Class: Sidekiq::Redeploy::Loader
- Inherits:
-
Object
- Object
- Sidekiq::Redeploy::Loader
- Defined in:
- lib/sidekiq/redeploy/loader.rb
Overview
Loads sidekiq process and monitors for redeploy
Constant Summary collapse
- USR2 =
Signal to sidekiq redeploy loader to restart a new Sidekiq process
'USR2'
- TTIN =
Signal to sidekiq to print backtraces for all threads
'TTIN'
- TSTP =
Signal to sidekiq that it will be shutting down soon and it should stop taking jobs.
'TSTP'
- TERM =
Signal to shutdown the loader after shutdown of sidekiq process
'TERM'
- INT =
Signal to shutdown the loader after shutdown of sidekiq process
'INT'
- SIGNALS =
[INT, TERM, USR2, TTIN].freeze
Instance Method Summary collapse
-
#initialize(deployer:, sidekiq_app: nil, logger: Logger.new($stdout), config: {}, num_processes: 1) ⇒ Loader
constructor
A new instance of Loader.
- #run ⇒ Object
Constructor Details
#initialize(deployer:, sidekiq_app: nil, logger: Logger.new($stdout), config: {}, num_processes: 1) ⇒ Loader
Returns a new instance of Loader.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/sidekiq/redeploy/loader.rb', line 18 def initialize(deployer:, sidekiq_app: nil, logger: Logger.new($stdout), config: {}, num_processes: 1) require 'sidekiq/cli' @reload_sidekiq = false @exit_loader = false @loader_pid = ::Process.pid @logger = logger @signal_delay = config[:signal_delay] || 1 @watch_delay = config[:watch_delay] || 30 @watch_time = Time.now @loop_delay = config[:loop_delay] || 0.5 @deployer = deployer @sidekiq_app = sidekiq_app @num_processes = num_processes || 1 @sidekiq_pids = [] end |
Instance Method Details
#run ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/sidekiq/redeploy/loader.rb', line 34 def run log "Starting sidekiq reloader... pid=#{@loader_pid}" trap_signals fork_sidekiq process_loop log 'Waiting for Sidekiq process to end' ::Process.waitall log 'Shutting down sidekiq reloader' rescue StandardError => e log "Error in sidekiq loader: #{e.}" log e.backtrace.join("\n") stop_sidekiq(@sidekiq_pids) ::Process.waitall exit 1 end |