Class: Sneakers::CLI

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

Constant Summary collapse

SNEAKERS =
<<-EOF

    __
,--'  >  Sneakers
`=====

EOF
SNEAKERS

Instance Method Summary collapse

Instance Method Details

#work(workers = "") ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/sneakers/cli.rb', line 33

def work(workers = "")
  opts = {
    :daemonize => !!options[:daemonize]
  }

  opts[:log] = options[:log] || (opts[:daemonize] ? 'sneakers.log' : STDOUT)
  opts[:pid_path] = options[:pid_path] if options[:pid_path]

  if opts[:daemonize]
    puts "*** DEPRACATED: self-daemonization '--daemonize' is considered a bad practice, which is why this feature will be removed in future versions. Please run Sneakers in front, and use things like upstart, systemd, or supervisor to manage it as a daemon."
  end


  Sneakers.configure(opts)

  require_boot File.expand_path(options[:require]) if options[:require]

  if workers.empty?
    workers = Sneakers::Worker::Classes
  else
    workers, missing_workers = Sneakers::Utils.parse_workers(workers)
  end

  unless missing_workers.nil? || missing_workers.empty?
    say "Missing workers: #{missing_workers.join(', ')}" if missing_workers
    say "Did you `require` properly?"
    return
  end

  if workers.empty?
    say <<-EOF
    Error: No workers found.
    Please require your worker classes before specifying in CLI

      $ sneakers work FooWorker
                      ^- require this in your code

    EOF
    return
  end

  r = Sneakers::Runner.new(workers)

  pid = Sneakers::CONFIG[:pid_path]

  say SNEAKERS
  say "Workers ....: #{em workers.join(', ')}"
  say "Log ........: #{em (Sneakers::CONFIG[:log] == STDOUT ? 'Console' : Sneakers::CONFIG[:log]) }"
  say "PID ........: #{em pid}"
  say ""
  say (" "*31)+"Process control"
  say "="*80
  say "Stop (nicely) ..............: kill -SIGTERM `cat #{pid}`"
  say "Stop (immediate) ...........: kill -SIGQUIT `cat #{pid}`"
  say "Restart (nicely) ...........: kill -SIGUSR1 `cat #{pid}`"
  say "Restart (immediate) ........: kill -SIGHUP `cat #{pid}`"
  say "Reconfigure ................: kill -SIGUSR2 `cat #{pid}`"
  say "Scale workers ..............: reconfigure, then restart"
  say "="*80
  say ""

  if options[:debug]
    say "==== configuration ==="
    say Sneakers::CONFIG.inspect
    say "======================"
  end

  r.run
end