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

Instance Method Summary collapse

Methods included from Util

#constantize, #logger, #process_id, #redis, #watchdog

Constructor Details

#initializeCLI

Returns a new instance of CLI.



44
45
46
# File 'lib/sidekiq/cli.rb', line 44

def initialize
  @code = nil
end

Instance Attribute Details

#codeObject

Used for CLI testing



41
42
43
# File 'lib/sidekiq/cli.rb', line 41

def code
  @code
end

#managerObject

Returns the value of attribute manager.



42
43
44
# File 'lib/sidekiq/cli.rb', line 42

def manager
  @manager
end

Instance Method Details

#parse(args = ARGV) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/sidekiq/cli.rb', line 48

def parse(args=ARGV)
  @code = nil
  Sidekiq.logger

  cli = parse_options(args)
  config = parse_config(cli)
  options.merge!(config.merge(cli))

  Sidekiq.logger.level = Logger::DEBUG if options[:verbose]
  Celluloid.logger = nil

  validate!
  write_pid
  boot_system
end

#runObject



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/sidekiq/cli.rb', line 64

def run
  @manager = Sidekiq::Manager.new(options)
  poller = Sidekiq::Retry::Poller.new
  begin
    logger.info 'Starting processing, hit Ctrl-C to stop'
    @manager.start!
    poller.poll!
    sleep
  rescue Interrupt
    logger.info 'Shutting down'
    poller.terminate! if poller.alive?
    @manager.stop!(:shutdown => true, :timeout => options[:timeout])
    @manager.wait(:shutdown)
    # Explicitly exit so busy Processor threads can't block
    # process shutdown.
    exit(0)
  end
end