Commit e2aa56ad authored by Marius Bobin's avatar Marius Bobin

Prevent auto retry of builds dropped because of exceeded quota

Prevent auto retry of builds dropped because of exceeded quota or no
matching runners.
parent 0faaa6a9
......@@ -7,6 +7,11 @@ class Gitlab::Ci::Build::AutoRetry
scheduler_failure: 2
}.freeze
RETRY_OVERRIDES = {
ci_quota_exceeded: 0,
no_matching_runner: 0
}.freeze
def initialize(build)
@build = build
end
......@@ -19,13 +24,18 @@ class Gitlab::Ci::Build::AutoRetry
private
delegate :failure_reason, to: :@build
def within_max_retry_limit?
max_allowed_retries > 0 && max_allowed_retries > @build.retries_count
end
def max_allowed_retries
strong_memoize(:max_allowed_retries) do
options_retry_max || DEFAULT_RETRIES.fetch(@build.failure_reason.to_sym, 0)
RETRY_OVERRIDES[failure_reason.to_sym] ||
options_retry_max ||
DEFAULT_RETRIES[failure_reason.to_sym] ||
0
end
end
......@@ -38,7 +48,7 @@ class Gitlab::Ci::Build::AutoRetry
end
def retry_on_reason_or_always?
options_retry_when.include?(@build.failure_reason.to_s) ||
options_retry_when.include?(failure_reason.to_s) ||
options_retry_when.include?('always')
end
......
......@@ -8,7 +8,7 @@ RSpec.describe Gitlab::Ci::Build::AutoRetry do
describe '#allowed?' do
using RSpec::Parameterized::TableSyntax
let(:build) { create(:ci_build) }
let(:build) { build_stubbed(:ci_build) }
subject { auto_retry.allowed? }
......@@ -22,6 +22,8 @@ RSpec.describe Gitlab::Ci::Build::AutoRetry do
"not matching reason" | 0 | { when: %w[script_error], max: 2 } | :api_failure | false
"scheduler failure override" | 1 | { when: %w[scheduler_failure], max: 1 } | :scheduler_failure | false
"default for scheduler failure" | 1 | {} | :scheduler_failure | true
"quota is exceeded" | 0 | { max: 2 } | :ci_quota_exceeded | false
"no matching runner" | 0 | { max: 2 } | :no_matching_runner | false
end
with_them do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment