Class: Juici::Watcher

Inherits:
Thread
  • Object
show all
Defined in:
lib/juici/watcher.rb

Class Method Summary collapse

Class Method Details

.catch_childObject

Hook for testing



35
36
37
# File 'lib/juici/watcher.rb', line 35

def self.catch_child
  Process.wait2(-1, Process::WNOHANG)
end

.mainloopObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/juici/watcher.rb', line 10

def self.mainloop
  #XXX No classvariables ever!
  loop do
    begin
      pid, status = catch_child
    rescue Errno::ECHILD
      # No children available, sleep for a while until some might exist
      # TODO: It'd be a nice optimisation to actually die here, and
      # optionally start a worker if we're the first child
      sleep 5
      next
    end
    next unless pid
    build = $build_queue.get_build_by_pid(pid)

    if status == 0
      build.success!
    else
      build.failure!
    end
    $build_queue.bump! if $build_queue
  end
end

.start!Object



4
5
6
7
8
# File 'lib/juici/watcher.rb', line 4

def self.start!
  new do
    self.mainloop
  end
end