Class: RFlow::ChildProcess

Inherits:
Object
  • Object
show all
Defined in:
lib/rflow/child_process.rb

Overview

Encapsulates a child process being managed by RFlow.

Direct Known Subclasses

Broker, Shard::Worker

Constant Summary collapse

SIGINFO =

Symbolic constant for SIGINFO as this is only defined on BSD and not in Ruby.

29

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, role = name) ⇒ ChildProcess

Returns a new instance of ChildProcess.

Parameters:

  • name (String)

    process name

  • role (String) (defaults to: name)

    role to be played by the process, for logging (Master, Broker, etc.)



18
19
20
21
# File 'lib/rflow/child_process.rb', line 18

def initialize(name, role = name)
  @name = name
  @role = role
end

Instance Attribute Details

#nameString (readonly)

The name of the child process.

Returns:

  • (String)


11
12
13
# File 'lib/rflow/child_process.rb', line 11

def name
  @name
end

#pidFixnum (readonly)

The PID of the child process.

Returns:

  • (Fixnum)


8
9
10
# File 'lib/rflow/child_process.rb', line 8

def pid
  @pid
end

Instance Method Details

#shutdown!(signal) ⇒ void

This method returns an undefined value.

Called when the child process needs to be shut down, before it dies. Clears signal handlers.

Parameters:

  • signal (String)

    SIG*, whichever signal caused the shutdown



65
66
67
68
# File 'lib/rflow/child_process.rb', line 65

def shutdown!(signal)
  RFlow.logger.info "Shutting down due to #{signal}"
  unhandle_signals
end

#spawn!void

This method returns an undefined value.

Launch another process to execute the child. The parent process retains the original worker object (with pid and IPC pipe) to allow for process management. Parent will return once the child starts; child will update its process name, detach from the process group, set up signal handlers, and execute #run_child_process; when that returns, it will exit with return code 0.



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/rflow/child_process.rb', line 31

def spawn!
  establish_child_pipe
  drop_database_connections

  @pid = fork
  if @pid
    return_after_child_starts
  else
    run_child_process
  end
end