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.



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

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.



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

def progress
  @progress
end

#totalObject (readonly)

Returns the value of attribute total.



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

def total
  @total
end

Class Method Details

.from_uri(uri, config) ⇒ Object



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

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

Instance Method Details

#acknowledgeObject



109
110
111
112
# File 'lib/ci/queue/static.rb', line 109

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

#boot_heartbeat_process!Object



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

def boot_heartbeat_process!; end

#buildObject



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

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

#created_at=(timestamp) ⇒ Object



69
70
71
# File 'lib/ci/queue/static.rb', line 69

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

#distributed?Boolean

Returns:

  • (Boolean)


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

def distributed?
  false
end

#ensure_heartbeat_thread_alive!Object



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

def ensure_heartbeat_thread_alive!; end

#exhausted?Boolean

Returns:

  • (Boolean)


105
106
107
# File 'lib/ci/queue/static.rb', line 105

def exhausted?
  @queue.empty?
end

#expired?Boolean

Returns:

  • (Boolean)


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

def expired?
  (@created_at.to_f + TEN_MINUTES) < CI::Queue.time_now.to_f
end

#increment_test_failedObject



114
115
116
# File 'lib/ci/queue/static.rb', line 114

def increment_test_failed(...)
  @test_failed = test_failed + 1
end

#max_test_failed?Boolean

Returns:

  • (Boolean)


122
123
124
125
126
# File 'lib/ci/queue/static.rb', line 122

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

  test_failed >= config.max_test_failed
end

#pollObject



97
98
99
100
101
102
103
# File 'lib/ci/queue/static.rb', line 97

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

#populate(tests, random: nil) ⇒ Object



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

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

#populated?Boolean

Returns:

  • (Boolean)


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

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

#queue_initialized?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/ci/queue/static.rb', line 65

def queue_initialized?
  true
end

#remainingObject



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

def remaining
  @queue.size
end

#report_worker_error(error) ⇒ Object



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

def report_worker_error(error); end

#requeue(test) ⇒ Object



128
129
130
131
132
133
134
135
# File 'lib/ci/queue/static.rb', line 128

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



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

def retry_queue
  self
end

#runningObject



93
94
95
# File 'lib/ci/queue/static.rb', line 93

def running
  reserved_tests.empty? ? 0 : 1
end

#shutdown!Object



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

def shutdown!
  @shutdown = true
end

#sizeObject



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

def size
  @queue.size
end

#stop_heartbeat!Object



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

def stop_heartbeat!; end

#supervisorObject

Raises:

  • (NotImplementedError)


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

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

#test_failedObject



118
119
120
# File 'lib/ci/queue/static.rb', line 118

def test_failed
  @test_failed ||= 0
end

#to_aObject



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

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

#with_heartbeat(id) ⇒ Object



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

def with_heartbeat(id)
  yield
end