Class: BPCI::Queue

Inherits:
Object
  • Object
show all
Defined in:
lib/bpci/queue.rb

Overview

An in memory queue used for maintaining an order list of requested builds.

Instance Method Summary collapse

Constructor Details

#initialize(enabled, verbose = false) ⇒ Queue

enabled - determines whether builds should be queued or not.



6
7
8
9
10
11
12
# File 'lib/bpci/queue.rb', line 6

def initialize(enabled, verbose=false)
  @enabled = enabled
  @verbose = verbose
  @queue = []

  log("Build queueing enabled") if enabled
end

Instance Method Details

#append_unless_already_exists(branch) ⇒ Object

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



21
22
23
24
25
26
27
# File 'lib/bpci/queue.rb', line 21

def append_unless_already_exists(branch)
  return unless enabled?
  unless @queue.include? branch
    @queue << branch
    log "#{Time.now.to_i}: Queueing #{branch}"
  end
end

#enabled?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/bpci/queue.rb', line 46

def enabled?
  @enabled
end

#next_branch_to_buildObject

Returns a String of the next branch to build



30
31
32
33
34
# File 'lib/bpci/queue.rb', line 30

def next_branch_to_build
  branch = @queue.shift
  log "#{Time.now.to_i}: De-queueing #{branch}"
  branch
end

#waiting?Boolean

Returns true if there are requested builds waiting and false otherwise.

Returns:

  • (Boolean)


38
39
40
41
42
43
44
# File 'lib/bpci/queue.rb', line 38

def waiting?
  if enabled?
    not @queue.empty?
  else
    false
  end
end