Class: Strelka::MultiRunner

Inherits:
Object
  • Object
show all
Extended by:
Loggability
Includes:
SignalHandling
Defined in:
lib/strelka/multirunner.rb

Overview

Load multiple simultaneous Strelka handlers (of a single type) with proper signal handling.

Constant Summary collapse

QUEUE_SIGS =

Signals we understand.

[ :QUIT, :INT, :TERM, :CHLD ]

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SignalHandling

#ignore_signals, #reset_signal_traps, #set_signal_traps, #set_up_signal_handling, #simulate_signal, #wait_for_signals, #wake_up, #with_signal_handler

Constructor Details

#initialize(app_class, number = 2) ⇒ MultiRunner

Create a new multirunner instance given a handler app_class, and the number of instances to start.



25
26
27
28
29
30
31
32
# File 'lib/strelka/multirunner.rb', line 25

def initialize( app_class, number=2 )
	@handler_pids = []
	@running      = false
	@app_class    = app_class
	@number       = number

	self.set_up_signal_handling
end

Instance Attribute Details

#app_classObject (readonly)

The class name of the handler.



44
45
46
# File 'lib/strelka/multirunner.rb', line 44

def app_class
  @app_class
end

#handler_pidsObject (readonly)

The child handler pids.



35
36
37
# File 'lib/strelka/multirunner.rb', line 35

def handler_pids
  @handler_pids
end

#numberObject (readonly)

How many handler children to manage.



41
42
43
# File 'lib/strelka/multirunner.rb', line 41

def number
  @number
end

#runningObject (readonly)

In this instance currently managing children?



38
39
40
# File 'lib/strelka/multirunner.rb', line 38

def running
  @running
end

Instance Method Details

#runObject

Start the child handlers via fork(), block for signals.



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/strelka/multirunner.rb', line 48

def run
	@running = true

	# Set up traps for common signals
	self.set_signal_traps( *QUEUE_SIGS )

	self.log.debug "Starting multirunner loop..."
	self.spawn_children
	while self.running
		self.reap_children if self.wait_for_signals
	end
	self.log.debug "Ending multirunner."

	# Restore the default signal handlers
	self.reset_signal_traps( *QUEUE_SIGS )

	return
end