Class: RFlow::ChildProcess

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

Direct Known Subclasses

Broker, Shard::Worker

Constant Summary collapse

SIGINFO =
29

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, role = name) ⇒ ChildProcess

Returns a new instance of ChildProcess.



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

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

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/rflow/child_process.rb', line 5

def name
  @name
end

#pidObject (readonly)

Returns the value of attribute pid.



5
6
7
# File 'lib/rflow/child_process.rb', line 5

def pid
  @pid
end

Instance Method Details

#run_child_processObject



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

def run_child_process
  @child_pipe_w.close
  register_logging_context
  update_process_name
  detach_process_group
  handle_signals

  RFlow.logger.info "#{@role} started"
  run_process
  exit 0
ensure
  unhandle_signals
end

#run_processObject



43
# File 'lib/rflow/child_process.rb', line 43

def run_process; end

#shutdown!(signal) ⇒ Object



45
46
47
48
# File 'lib/rflow/child_process.rb', line 45

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

#spawn!Object

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



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rflow/child_process.rb', line 17

def spawn!
  establish_child_pipe
  drop_database_connections

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