Class: Juici::BuildQueue

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

Instance Method Summary collapse

Constructor Details

#initializeBuildQueue

Returns a new instance of BuildQueue.



7
8
9
10
11
12
# File 'lib/juici/build_queue.rb', line 7

def initialize
  @builds = []
  @child_pids = []
  # This is never expired, for now
  @builds_by_pid = {}
end

Instance Method Details

#<<(other) ⇒ Object

Pushing a Build object into the BuildQueue is expressing that you want it run



23
24
25
26
# File 'lib/juici/build_queue.rb', line 23

def <<(other)
  @builds << other
  bump!
end

#bump!Object

Magic hook that starts a process if there’s a good reason to. Stopgap measure that means you can knock on this if there’s a chance we should start a process



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/juici/build_queue.rb', line 45

def bump!
  update_children
  if not_working? && work_to_do?
    Juici.dbgp "Starting another child process"
    next_child.tap do |child|
      pid = child.build!
      @child_pids << pid
      @builds_by_pid[pid] = child
    end
  else
    Juici.dbgp "I have quite enough to do"
  end
end

#current_min_priorityObject



28
29
30
# File 'lib/juici/build_queue.rb', line 28

def current_min_priority
  @builds.collect(&:priority).compact.min || 1
end

#get_build_by_pid(pid) ⇒ Object



71
72
73
# File 'lib/juici/build_queue.rb', line 71

def get_build_by_pid(pid)
  @builds_by_pid[pid]
end

#next_childObject



32
33
34
# File 'lib/juici/build_queue.rb', line 32

def next_child
  @builds.sort_by(&:priority).first
end

#not_working?Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/juici/build_queue.rb', line 75

def not_working?
  @child_pids.length == 0
end

#purge(by, build) ⇒ Object



36
37
38
39
40
# File 'lib/juici/build_queue.rb', line 36

def purge(by, build)
  @builds.reject! do |i|
    build.send(by) == i.send(by)
  end
end

#shutdown!Object



14
15
16
17
18
19
# File 'lib/juici/build_queue.rb', line 14

def shutdown!
  @child_pids.each do |pid|
    ::Juici.dbgp "Killing off child pid #{pid}"
    Process.kill(15, pid)
  end
end

#update_childrenObject



59
60
61
62
63
64
65
66
67
68
69
# File 'lib/juici/build_queue.rb', line 59

def update_children
  @child_pids.select! do |pid|
    return false if pid.nil?
    begin
      Process.kill(0, pid)
      true
    rescue Errno::ESRCH
      false
    end
  end
end

#work_to_do?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/juici/build_queue.rb', line 79

def work_to_do?
  @builds.length > 0
end