Class: Creeper::CLI

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

Constant Summary

Constants included from Util

Util::EXPIRY

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util

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

Methods included from ExceptionHandler

#handle_exception

Constructor Details

#initializeCLI

Returns a new instance of CLI.



58
59
60
61
62
# File 'lib/creeper/cli.rb', line 58

def initialize
  @code = nil
  @interrupt_mutex = Mutex.new
  @interrupted = false
end

Instance Attribute Details

#codeObject

Used for CLI testing



55
56
57
# File 'lib/creeper/cli.rb', line 55

def code
  @code
end

#managerObject

Returns the value of attribute manager.



56
57
58
# File 'lib/creeper/cli.rb', line 56

def manager
  @manager
end

Instance Method Details

#interruptObject



96
97
98
99
100
101
102
103
# File 'lib/creeper/cli.rb', line 96

def interrupt
  @interrupt_mutex.synchronize do
    unless @interrupted
      @interrupted = true
      Thread.main.raise Interrupt
    end
  end
end

#parse(args = ARGV) ⇒ Object



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

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

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

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

  validate!
  write_pid
  boot_system
end

#runObject



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/creeper/cli.rb', line 80

def run
  @manager = Creeper::Manager.new(options)
  begin
    logger.info 'Starting processing, hit Ctrl-C to stop'
    @manager.start!
    sleep
  rescue Interrupt
    logger.info 'Shutting down'
    @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