Class: October::Watchdog

Inherits:
Object
  • Object
show all
Defined in:
lib/october/watchdog.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root, env = nil) ⇒ Watchdog

Returns a new instance of Watchdog.



5
6
7
8
# File 'lib/october/watchdog.rb', line 5

def initialize(root, env = nil)
  @root = root
  @env = env
end

Instance Attribute Details

#childObject (readonly)

Returns the value of attribute child.



3
4
5
# File 'lib/october/watchdog.rb', line 3

def child
  @child
end

#envObject (readonly)

Returns the value of attribute env.



3
4
5
# File 'lib/october/watchdog.rb', line 3

def env
  @env
end

#rootObject (readonly)

Returns the value of attribute root.



3
4
5
# File 'lib/october/watchdog.rb', line 3

def root
  @root
end

Instance Method Details

#loop!Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/october/watchdog.rb', line 21

def loop!
  loop do
    begin
      Process.wait(spawn!)
      warn "process #{child} ended"
    rescue Errno::ECHILD
      warn "process #{child} died or was killed"
    end

    warn "spawning new one in next iteration"

    sleep(1) # throttle spawning in case anything fails
  end
end

#spawn!Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/october/watchdog.rb', line 10

def spawn!
  @child = fork do
    ENV['OCTOBER_ENV'] ||= env

    require File.join(root, "boot")
    require 'october'

    October::Base.start
  end
end