Class: Sidekiq::CLI

Inherits:
Object
  • Object
show all
Includes:
Util, Singleton
Defined in:
lib/sidekiq/cli.rb

Constant Summary

Constants included from Util

Util::EXPIRY

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Util

#fire_event, #hostname, #identity, #logger, #redis, #watchdog

Methods included from ExceptionHandler

#handle_exception

Constructor Details

#initializeCLI

Returns a new instance of CLI.



30
31
32
# File 'lib/sidekiq/cli.rb', line 30

def initialize
  @code = nil
end

Instance Attribute Details

#codeObject

Used for CLI testing



26
27
28
# File 'lib/sidekiq/cli.rb', line 26

def code
  @code
end

#environmentObject

Returns the value of attribute environment.



28
29
30
# File 'lib/sidekiq/cli.rb', line 28

def environment
  @environment
end

#launcherObject

Returns the value of attribute launcher.



27
28
29
# File 'lib/sidekiq/cli.rb', line 27

def launcher
  @launcher
end

Class Method Details



94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/sidekiq/cli.rb', line 94

def self.banner
%q{         s
      ss
 sss  sss         ss
 s  sss s   ssss sss   ____  _     _      _    _
 s     sssss ssss     / ___|(_) __| | ___| | _(_) __ _
s         sss         \___ \| |/ _` |/ _ \ |/ / |/ _` |
s sssss  s             ___) | | (_| |  __/   <| | (_| |
ss    s  s            |____/|_|\__,_|\___|_|\_\_|\__, |
s     s s                                           |_|
      s s
     sss
     sss }
end

Instance Method Details

#parse(args = ARGV) ⇒ Object



34
35
36
37
38
39
40
41
42
43
# File 'lib/sidekiq/cli.rb', line 34

def parse(args=ARGV)
  @code = nil

  setup_options(args)
  initialize_logger
  validate!
  daemonize
  write_pid
  load_celluloid
end

#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.



48
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
# File 'lib/sidekiq/cli.rb', line 48

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/pro" unless defined?(::Sidekiq::Pro)

  fire_event(:startup)

  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
    fire_event(:shutdown)
    # Explicitly exit so busy Processor threads can't block
    # process shutdown.
    exit(0)
  end
end