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



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

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



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

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)


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

def exhausted?
  @queue.empty?
end

#expired?Boolean

Returns:

  • (Boolean)


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

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

#increment_test_failedObject



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

def increment_test_failed
  @test_failed = test_failed + 1
end

#max_test_failed?Boolean

Returns:

  • (Boolean)


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

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

  test_failed >= config.max_test_failed
end

#pollObject



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

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)


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

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

#remainingObject



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

def remaining
  @queue.size
end

#requeue(test) ⇒ Object



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

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



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

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



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

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



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

def test_failed
  @test_failed ||= 0
end

#to_aObject



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

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