Class: Delayed::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/delayed/cli.rb

Instance Method Summary collapse

Constructor Details

#initialize(args = ARGV) ⇒ CLI

Returns a new instance of CLI.



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/delayed/cli.rb', line 5

def initialize(args = ARGV)
  @args = args
  # config that will be applied on Settings and passed to the created Pool
  @config = {}
  # CLI options that will be kept to this class
  @options = {
    :config_file => Settings.default_worker_config_name,
    :pid_folder => Settings.expand_rails_path("tmp/pids"),
    :tail_logs => true, # only in FG mode
  }
end

Instance Method Details

#parse_cli_options!Object



48
49
50
51
# File 'lib/delayed/cli.rb', line 48

def parse_cli_options!
  option_parser.parse!(@args)
  @options
end

#runObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/delayed/cli.rb', line 17

def run
  parse_cli_options!
  load_and_apply_config!

  command = @args.shift
  case command
  when 'start'
    exit 1 if daemon.status(print: :alive) == :running
    daemon.daemonize!
    start
  when 'stop'
    daemon.stop(kill: @options[:kill])
  when 'run'
    start
  when 'status'
    if daemon.status
      exit 0
    else
      exit 1
    end
  when 'restart'
    daemon.stop(kill: @options[:kill])
    daemon.daemonize!
    start
  when nil
    puts option_parser.to_s
  else
    raise("Unknown command: #{command.inspect}")
  end
end