Skip to content
Snippets Groups Projects

Make register job service to be resillient

Merged Kamil Trzciński requested to merge make-register-job-service-to-be-resillient into master
All threads resolved!
10 files
+ 188
101
Compare changes
  • Side-by-side
  • Inline
Files
10
+ 27
9
@@ -35,6 +35,10 @@ class Build < CommitStatus
@@ -35,6 +35,10 @@ class Build < CommitStatus
refspecs: -> (build) { build.merge_request_ref? }
refspecs: -> (build) { build.merge_request_ref? }
}.freeze
}.freeze
 
DEFAULT_RETRIES = {
 
scheduler_failure: 2
 
}.freeze
 
has_one :deployment, as: :deployable, class_name: 'Deployment'
has_one :deployment, as: :deployable, class_name: 'Deployment'
has_many :trace_sections, class_name: 'Ci::BuildTraceSection'
has_many :trace_sections, class_name: 'Ci::BuildTraceSection'
has_many :trace_chunks, class_name: 'Ci::BuildTraceChunk', foreign_key: :build_id
has_many :trace_chunks, class_name: 'Ci::BuildTraceChunk', foreign_key: :build_id
@@ -372,18 +376,25 @@ def retries_count
@@ -372,18 +376,25 @@ def retries_count
pipeline.builds.retried.where(name: self.name).count
pipeline.builds.retried.where(name: self.name).count
end
end
def retries_max
def retry_failure?
normalized_retry.fetch(:max, 0)
max_allowed_retries = nil
 
max_allowed_retries ||= options_retry_max if retry_on_reason_or_always?
 
max_allowed_retries ||= DEFAULT_RETRIES.fetch(failure_reason.to_sym, 0)
 
 
max_allowed_retries > 0 && retries_count < max_allowed_retries
end
end
def retry_when
def options_retry_max
normalized_retry.fetch(:when, ['always'])
options_retry[:max]
end
end
def retry_failure?
def options_retry_when
return false if retries_max.zero? || retries_count >= retries_max
options_retry.fetch(:when, ['always'])
 
end
retry_when.include?('always') || retry_when.include?(failure_reason.to_s)
def retry_on_reason_or_always?
 
options_retry_when.include?(failure_reason.to_s) ||
 
options_retry_when.include?('always')
end
end
def latest?
def latest?
@@ -831,6 +842,13 @@ def deployment_status
@@ -831,6 +842,13 @@ def deployment_status
:creating
:creating
end
end
 
# Consider this object to have a structural integrity problems
 
def doom!
 
update_columns(
 
status: :failed,
 
failure_reason: :data_integrity_failure)
 
end
 
private
private
def successful_deployment_status
def successful_deployment_status
@@ -875,8 +893,8 @@ def environment_url
@@ -875,8 +893,8 @@ def environment_url
# format, but builds created before GitLab 11.5 and saved in database still
# format, but builds created before GitLab 11.5 and saved in database still
# have the old integer only format. This method returns the retry option
# have the old integer only format. This method returns the retry option
# normalized as a hash in 11.5+ format.
# normalized as a hash in 11.5+ format.
def normalized_retry
def options_retry
strong_memoize(:normalized_retry) do
strong_memoize(:options_retry) do
value = options&.dig(:retry)
value = options&.dig(:retry)
value = value.is_a?(Integer) ? { max: value } : value.to_h
value = value.is_a?(Integer) ? { max: value } : value.to_h
value.with_indifferent_access
value.with_indifferent_access
Loading