Class: Delayed::CLI

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

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = ARGV) ⇒ CLI

Returns a new instance of CLI.


13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/delayed/cli.rb', line 13

def initialize(args = ARGV)
  self.class.instance = self

  @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

Class Attribute Details

.instanceObject

Returns the value of attribute instance


8
9
10
# File 'lib/delayed/cli.rb', line 8

def instance
  @instance
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config


11
12
13
# File 'lib/delayed/cli.rb', line 11

def config
  @config
end

Instance Method Details

#parse_cli_options!Object


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

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

#runObject


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/delayed/cli.rb', line 27

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