Class: RFlow::ChildProcess

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

Direct Known Subclasses

Broker, Shard::Worker

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, role = name) ⇒ ChildProcess

Returns a new instance of ChildProcess.



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

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

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/rflow/child_process.rb', line 3

def name
  @name
end

#pidObject (readonly)

Returns the value of attribute pid.



3
4
5
# File 'lib/rflow/child_process.rb', line 3

def pid
  @pid
end

Instance Method Details

#run_child_processObject



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rflow/child_process.rb', line 25

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



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

def run_process; end

#shutdown!(signal) ⇒ Object



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

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



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/rflow/child_process.rb', line 13

def spawn!
  establish_child_pipe
  drop_database_connections

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