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.



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

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.



6
7
8
# File 'lib/delayed/cli.rb', line 6

def instance
  @instance
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



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

def config
  @config
end

Instance Method Details

#parse_cli_options!Object



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

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

#runObject



25
26
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
# File 'lib/delayed/cli.rb', line 25

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