Method: Sidekiq::CLI#run

Defined in:
lib/sidekiq/cli.rb

#runObject

Code within this method is not tested because it alters global process state irreversibly. PRs which improve the test coverage of Sidekiq::CLI are welcomed.



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/sidekiq/cli.rb', line 49

def run
  boot_system
  print_banner

  self_read, self_write = IO.pipe

  %w(INT TERM USR1 USR2 TTIN).each do |sig|
    begin
      trap sig do
        self_write.puts(sig)
      end
    rescue ArgumentError
      puts "Signal #{sig} not supported"
    end
  end

  logger.info "Running in #{RUBY_DESCRIPTION}"
  logger.info Sidekiq::LICENSE
  logger.info "Upgrade to Sidekiq Pro for more features and support: http://sidekiq.org" unless defined?(::Sidekiq::Pro)

  # touch the connection pool so it is created before we
  # fire startup and start multithreading.
  ver = Sidekiq.redis_info['redis_version']
  raise "You are using Redis v#{ver}, Sidekiq requires Redis v2.8.0 or greater" if ver < '2.8'

  # Before this point, the process is initializing with just the main thread.
  # Starting here the process will now have multiple threads running.
  fire_event(:startup)

  logger.debug { "Client Middleware: #{Sidekiq.client_middleware.map(&:klass).join(', ')}" }
  logger.debug { "Server Middleware: #{Sidekiq.server_middleware.map(&:klass).join(', ')}" }

  if !options[:daemon]
    logger.info 'Starting processing, hit Ctrl-C to stop'
  end

  require 'sidekiq/launcher'
  @launcher = Sidekiq::Launcher.new(options)

  begin
    launcher.run

    while readable_io = IO.select([self_read])
      signal = readable_io.first[0].gets.strip
      handle_signal(signal)
    end
  rescue Interrupt
    logger.info 'Shutting down'
    launcher.stop
    # Explicitly exit so busy Processor threads can't block
    # process shutdown.
    logger.info "Bye!"
    exit(0)
  end
end