Class: Shoryuken::Launcher

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/shoryuken/launcher.rb

Overview

Launches and coordinates Shoryuken’s message processing managers. Handles the lifecycle of the processing system including startup, shutdown, and health checks.

Instance Method Summary collapse

Methods included from Util

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

Constructor Details

#initializeLauncher

Initializes a new Launcher with managers for each processing group



10
11
12
13
# File 'lib/shoryuken/launcher.rb', line 10

def initialize
  @managers = create_managers
  @stopping = false
end

Instance Method Details

#healthy?Boolean

Checks if all processing groups are healthy

Returns:

  • (Boolean)

    true if all groups are running normally



73
74
75
76
77
78
# File 'lib/shoryuken/launcher.rb', line 73

def healthy?
  Shoryuken.groups.keys.all? do |group|
    manager = @managers.find { |m| m.group == group }
    manager && manager.running?
  end
end

#startvoid

This method returns an undefined value.

Starts the message processing system



29
30
31
32
33
34
# File 'lib/shoryuken/launcher.rb', line 29

def start
  logger.info { 'Starting' }

  start_callback
  start_managers
end

#stopvoid

This method returns an undefined value.

Gracefully stops all processing, waiting for in-flight messages



55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/shoryuken/launcher.rb', line 55

def stop
  @stopping = true
  fire_event(:quiet, true)

  initiate_stop

  stop_new_dispatching
  await_dispatching_in_progress

  executor.shutdown
  executor.wait_for_termination

  fire_event(:stopped)
end

#stop!void

This method returns an undefined value.

Forces an immediate stop of all processing



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/shoryuken/launcher.rb', line 39

def stop!
  @stopping = true
  initiate_stop

  # Don't await here so the timeout below is not delayed
  stop_new_dispatching

  executor.shutdown
  executor.kill unless executor.wait_for_termination(Shoryuken.options[:timeout])

  fire_event(:stopped)
end

#stopping?Boolean

Indicates whether the launcher is in the process of stopping.

This flag is set to true when either #stop or #stop! is called, and is used by ActiveJob adapters to signal jobs that they should checkpoint and prepare for graceful shutdown.

Returns:

  • (Boolean)

    true if stopping, false otherwise



22
23
24
# File 'lib/shoryuken/launcher.rb', line 22

def stopping?
  @stopping
end