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.



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

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



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

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



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

def run_process; end

#shutdown!(signal) ⇒ Object



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

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



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

def spawn!
  establish_child_pipe
  drop_database_connections

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