Class: Shoryuken::Runner

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

Overview

Runs the Shoryuken server process. Handles signal trapping, daemonization, and lifecycle management.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util

#elapsed, #fire_event, #logger, #unparse_queues, #worker_name

Instance Attribute Details

#launcherShoryuken::Launcher? (readonly)

Returns the launcher instance, or nil if not yet initialized.

Returns:



19
20
21
# File 'lib/shoryuken/runner.rb', line 19

def launcher
  @launcher
end

Instance Method Details

#healthy?Boolean

Checks if the server is healthy

Returns:

  • (Boolean)

    true if the launcher is running and healthy



67
68
69
# File 'lib/shoryuken/runner.rb', line 67

def healthy?
  (@launcher && @launcher.healthy?) || false
end

#run(options) ⇒ void

This method returns an undefined value.

Runs the Shoryuken server with the given options

Parameters:

  • options (Hash)

    runtime configuration options

Options Hash (options):

  • :daemon (Boolean)

    whether to daemonize the process

  • :pidfile (String)

    path to the PID file

  • :logfile (String)

    path to the log file

  • :config_file (String)

    path to the configuration file



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
57
58
59
60
61
62
# File 'lib/shoryuken/runner.rb', line 29

def run(options)
  self_read, self_write = IO.pipe

  %w[INT TERM USR1 TSTP TTIN].each do |sig|
    trap sig do
      self_write.puts(sig)
    end
  rescue ArgumentError
    puts "Signal #{sig} not supported"
  end

  loader = EnvironmentLoader.setup_options(options)

  daemonize(Shoryuken.options)
  write_pid(Shoryuken.options)

  loader.load

  initialize_concurrent_logger

  @launcher = Shoryuken::Launcher.new

  begin
    @launcher.start

    while (readable_io = IO.select([self_read]))
      signal = readable_io.first[0].gets.strip
      handle_signal(signal)
    end
  rescue Interrupt
    @launcher.stop!
    exit 0
  end
end