forked from defunkt/cijoe
/
queue.rb
55 lines (49 loc) · 1.23 KB
/
queue.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
class CIJoe
# An in memory queue used for maintaining an order list of requested
# builds.
class Queue
# enabled - determines whether builds should be queued or not.
def initialize(enabled, verbose=false)
@enabled = enabled
@verbose = verbose
@queue = []
log("Build queueing enabled") if enabled
end
# Public: Appends a branch to be built, unless it already exists
# within the queue.
#
# branch - the name of the branch to build or nil if the default
# should be built.
#
# Returns nothing
def append_unless_already_exists(branch)
return unless enabled?
unless @queue.include? branch
@queue << branch
log "#{Time.now.to_i}: Queueing #{branch}"
end
end
# Returns a String of the next branch to build
def next_branch_to_build
branch = @queue.shift
log "#{Time.now.to_i}: De-queueing #{branch}"
branch
end
# Returns true if there are requested builds waiting and false
# otherwise.
def waiting?
if enabled?
not @queue.empty?
else
false
end
end
protected
def log(msg)
puts msg if @verbose
end
def enabled?
@enabled
end
end
end