Class: CI::Queue::Static

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

Direct Known Subclasses

File, Grind, 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?, #release!, #report_failure!, #report_success!, #rescue_connection_errors, #retrying?

Constructor Details

#initialize(tests, config) ⇒ Static

Returns a new instance of Static.



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

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

Instance Attribute Details

#progressObject (readonly)

Returns the value of attribute progress.



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

def progress
  @progress
end

#totalObject (readonly)

Returns the value of attribute total.



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

def total
  @total
end

Class Method Details

.from_uri(uri, config) ⇒ Object



8
9
10
11
# File 'lib/ci/queue/static.rb', line 8

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

Instance Method Details

#acknowledge(test) ⇒ Object



62
63
64
65
# File 'lib/ci/queue/static.rb', line 62

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

#buildObject



23
24
25
# File 'lib/ci/queue/static.rb', line 23

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

#exhausted?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/ci/queue/static.rb', line 58

def exhausted?
  @queue.empty?
end

#increment_test_failedObject



67
68
69
# File 'lib/ci/queue/static.rb', line 67

def increment_test_failed
  @test_failed = test_failed + 1
end

#max_test_failed?Boolean

Returns:

  • (Boolean)


75
76
77
78
79
# File 'lib/ci/queue/static.rb', line 75

def max_test_failed?
  return false if config.max_test_failed.nil?

  test_failed >= config.max_test_failed
end

#pollObject



52
53
54
55
56
# File 'lib/ci/queue/static.rb', line 52

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

#populate(tests, random: nil) ⇒ Object



35
36
37
38
# File 'lib/ci/queue/static.rb', line 35

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

#populated?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/ci/queue/static.rb', line 40

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

#requeue(test) ⇒ Object



81
82
83
84
85
86
87
88
# File 'lib/ci/queue/static.rb', line 81

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_queueObject



31
32
33
# File 'lib/ci/queue/static.rb', line 31

def retry_queue
  self
end

#sizeObject



48
49
50
# File 'lib/ci/queue/static.rb', line 48

def size
  @queue.size
end

#supervisorObject

Raises:

  • (NotImplementedError)


27
28
29
# File 'lib/ci/queue/static.rb', line 27

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

#test_failedObject



71
72
73
# File 'lib/ci/queue/static.rb', line 71

def test_failed
  @test_failed ||= 0
end

#to_aObject



44
45
46
# File 'lib/ci/queue/static.rb', line 44

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