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 collapse

TEN_MINUTES =
60 * 10

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.



18
19
20
21
22
23
24
# File 'lib/ci/queue/static.rb', line 18

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

Instance Attribute Details

#progressObject (readonly)

Returns the value of attribute progress.



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

def progress
  @progress
end

#totalObject (readonly)

Returns the value of attribute total.



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

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



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

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

#buildObject



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

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

#created_at=(timestamp) ⇒ Object



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

def created_at=(timestamp)
  @created_at ||= timestamp
end

#distributed?Boolean

Returns:

  • (Boolean)


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

def distributed?
  false
end

#exhausted?Boolean

Returns:

  • (Boolean)


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

def exhausted?
  @queue.empty?
end

#expired?Boolean

Returns:

  • (Boolean)


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

def expired?
  (@created_at.to_f TEN_MINUTES) < Time.now.to_f
end

#increment_test_failedObject



86
87
88
# File 'lib/ci/queue/static.rb', line 86

def increment_test_failed
  @test_failed = test_failed + 1
end

#max_test_failed?Boolean

Returns:

  • (Boolean)


94
95
96
97
98
# File 'lib/ci/queue/static.rb', line 94

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

  test_failed >= config.max_test_failed
end

#pollObject



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

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

#populate(tests, random: nil) ⇒ Object



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

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

#populated?Boolean

Returns:

  • (Boolean)


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

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

#requeue(test) ⇒ Object



100
101
102
103
104
105
106
107
# File 'lib/ci/queue/static.rb', line 100

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



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

def retry_queue
  self
end

#shutdown!Object



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

def shutdown!
  @shutdown = true
end

#sizeObject



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

def size
  @queue.size
end

#supervisorObject

Raises:

  • (NotImplementedError)


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

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

#test_failedObject



90
91
92
# File 'lib/ci/queue/static.rb', line 90

def test_failed
  @test_failed ||= 0
end

#to_aObject



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

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