Method: PerfectQueue::Multiprocess::ForkProcessor#keepalive

Defined in:
lib/perfectqueue/multiprocess/fork_processor.rb

#keepaliveObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/perfectqueue/multiprocess/fork_processor.rb', line 56

def keepalive
  if @stop
    try_join
    return
  end

  if c = @cpm
    if c.killing_status != true
      # don't check status if killing status is immediate-killing
      begin
        # receive heartbeat
        keptalive = c.check_heartbeat(@child_heartbeat_limit)
        if !keptalive
          @log.error "Heartbeat broke out. Restarting child process id=#{@processor_id} pid=#{c.pid}."
          c.start_killing(true)
        end
      rescue EOFError
        @log.error "Heartbeat pipe is closed. Restarting child process id=#{@processor_id} pid=#{c.pid}."
        c.start_killing(true, @child_heartbeat_kill_delay)
      rescue
        @log.error "Unknown error: #{$!.class}: #{$!}: Restarting child process id=#{@processor_id} pid=#{c.pid}."
        $!.backtrace.each {|bt| @log.warn "\t#{bt}" }
        c.start_killing(true, @child_heartbeat_kill_delay)
      end
    end

    try_join
  end

  unless @cpm
    begin
      @cpm = fork_child
    rescue
      @log.error "Failed to fork child process id=#{@processor_id}: #{$!.class}: #{$!}"
      $!.backtrace.each {|bt| @log.warn "\t#{bt}" }
    end
  end

  nil
end