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



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

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

#boot_heartbeat_process!Object



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

def boot_heartbeat_process!; end

#buildObject



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

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

#created_at=(timestamp) ⇒ Object



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

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

#ensure_heartbeat_thread_alive!Object



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

def ensure_heartbeat_thread_alive!; end

#exhausted?Boolean

Returns:

  • (Boolean)


98
99
100
# File 'lib/ci/queue/static.rb', line 98

def exhausted?
  @queue.empty?
end

#expired?Boolean

Returns:

  • (Boolean)


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

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

#increment_test_failedObject



107
108
109
# File 'lib/ci/queue/static.rb', line 107

def increment_test_failed
  @test_failed = test_failed + 1
end

#max_test_failed?Boolean

Returns:

  • (Boolean)


115
116
117
118
119
# File 'lib/ci/queue/static.rb', line 115

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

  test_failed >= config.max_test_failed
end

#pollObject



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

def poll
  while !@shutdown && config.circuit_breakers.none?(&:open?) && !max_test_failed? && @reserved_test = @queue.shift
    yield index.fetch(@reserved_test)
  end
  @reserved_test = nil
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)


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

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

#remainingObject



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

def remaining
  @queue.size
end

#report_worker_error(error) ⇒ Object



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

def report_worker_error(error); end

#requeue(test) ⇒ Object



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

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

#runningObject



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

def running
  @reserved_test ? 1 : 0
end

#shutdown!Object



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

def shutdown!
  @shutdown = true
end

#sizeObject



79
80
81
# File 'lib/ci/queue/static.rb', line 79

def size
  @queue.size
end

#stop_heartbeat!Object



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

def stop_heartbeat!; 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



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

def test_failed
  @test_failed ||= 0
end

#to_aObject



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

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

#with_heartbeat(id) ⇒ Object



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

def with_heartbeat(id)
  yield
end