Class: CI::Queue::Static

Inherits:
Object
  • Object
show all
Includes:
Common
Defined in:
lib/ci/queue/static.rb

Direct Known Subclasses

File, Redis::Retry

Constant Summary

Constants included from Common

Common::CONNECTION_ERRORS

Instance Attribute Summary collapse

Attributes included from Common

#config

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Common

#flaky?, #report_failure!, #report_success!, #rescue_connection_errors

Constructor Details

#initialize(tests, config) ⇒ Static

Returns a new instance of Static.



14
15
16
17
18
19
# File 'lib/ci/queue/static.rb', line 14

def initialize(tests, config)
  @queue = tests
  @config = config
  @progress = 0
  @total = tests.size
end

Instance Attribute Details

#progress ⇒ Object (readonly)

Returns the value of attribute progress.



12
13
14
# File 'lib/ci/queue/static.rb', line 12

def progress
  @progress
end

#total ⇒ Object (readonly)

Returns the value of attribute total.



12
13
14
# File 'lib/ci/queue/static.rb', line 12

def total
  @total
end

Class Method Details

.from_uri(uri, config) ⇒ Object



6
7
8
9
# File 'lib/ci/queue/static.rb', line 6

def from_uri(uri, config)
  tests = uri.opaque.split(':').map { |t| CGI.unescape(t) }
  new(tests, config)
end

Instance Method Details

#acknowledge(test) ⇒ Object



60
61
62
63
# File 'lib/ci/queue/static.rb', line 60

def acknowledge(test)
  @progress += 1
  true
end

#build ⇒ Object



21
22
23
# File 'lib/ci/queue/static.rb', line 21

def build
  @build ||= BuildRecord.new(self)
end

#exhausted? ⇒ Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/ci/queue/static.rb', line 56

def exhausted?
  @queue.empty?
end

#poll ⇒ Object



50
51
52
53
54
# File 'lib/ci/queue/static.rb', line 50

def poll
  while !config.circuit_breaker.open? && test = @queue.shift
    yield index.fetch(test)
  end
end

#populate(tests, random: nil) ⇒ Object



33
34
35
36
# File 'lib/ci/queue/static.rb', line 33

def populate(tests, random: nil)
  @index = tests.map { |t| [t.id, t] }.to_h
  self
end

#populated? ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/ci/queue/static.rb', line 38

def populated?
  !!defined?(@index)
end

#requeue(test) ⇒ Object



65
66
67
68
69
70
71
# File 'lib/ci/queue/static.rb', line 65

def requeue(test)
  test_key = test.id
  return false unless should_requeue?(test_key)
  requeues[test_key] += 1
  @queue.unshift(test_key)
  true
end

#retry_queue ⇒ Object



29
30
31
# File 'lib/ci/queue/static.rb', line 29

def retry_queue
  self
end

#size ⇒ Object



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

def size
  @queue.size
end

#supervisor ⇒ Object

Raises:

  • (NotImplementedError)


25
26
27
# File 'lib/ci/queue/static.rb', line 25

def supervisor
  raise NotImplementedError, "This type of queue can't be supervised"
end

#to_a ⇒ Object



42
43
44
# File 'lib/ci/queue/static.rb', line 42

def to_a
  @queue.map { |i| index.fetch(i) }
end