2018-08-03 03:15:25 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-02-28 21:12:32 -05:00
|
|
|
module Ci
|
2018-03-05 11:35:06 -05:00
|
|
|
# The purpose of this class is to store Build related data that can be disposed.
|
|
|
|
# Data that should be persisted forever, should be stored with Ci::Build model.
|
2018-02-28 21:12:32 -05:00
|
|
|
class BuildMetadata < ActiveRecord::Base
|
|
|
|
extend Gitlab::Ci::Model
|
|
|
|
include Presentable
|
|
|
|
include ChronicDurationAttribute
|
|
|
|
|
|
|
|
self.table_name = 'ci_builds_metadata'
|
|
|
|
|
2019-01-29 08:40:47 -05:00
|
|
|
belongs_to :build, class_name: 'CommitStatus'
|
2018-03-20 20:20:15 -04:00
|
|
|
belongs_to :project
|
2018-02-28 21:12:32 -05:00
|
|
|
|
2018-09-02 10:35:15 -04:00
|
|
|
before_create :set_build_project
|
|
|
|
|
2018-03-26 12:58:35 -04:00
|
|
|
validates :build, presence: true
|
2018-09-02 10:35:15 -04:00
|
|
|
|
|
|
|
serialize :config_options, Serializers::JSON # rubocop:disable Cop/ActiveRecordSerialize
|
|
|
|
serialize :config_variables, Serializers::JSON # rubocop:disable Cop/ActiveRecordSerialize
|
2018-02-28 21:12:32 -05:00
|
|
|
|
2018-03-22 12:52:28 -04:00
|
|
|
chronic_duration_attr_reader :timeout_human_readable, :timeout
|
2018-03-20 20:20:15 -04:00
|
|
|
|
2018-02-28 21:12:32 -05:00
|
|
|
enum timeout_source: {
|
2018-03-05 11:35:06 -05:00
|
|
|
unknown_timeout_source: 1,
|
|
|
|
project_timeout_source: 2,
|
|
|
|
runner_timeout_source: 3
|
2018-02-28 21:12:32 -05:00
|
|
|
}
|
|
|
|
|
2018-03-26 11:47:46 -04:00
|
|
|
def update_timeout_state
|
2018-03-06 10:43:44 -05:00
|
|
|
return unless build.runner.present?
|
2018-03-05 11:35:06 -05:00
|
|
|
|
2018-03-22 12:52:28 -04:00
|
|
|
project_timeout = project&.build_timeout
|
2018-03-06 10:43:44 -05:00
|
|
|
timeout = [project_timeout, build.runner.maximum_timeout].compact.min
|
|
|
|
timeout_source = timeout < project_timeout ? :runner_timeout_source : :project_timeout_source
|
2018-03-05 11:35:06 -05:00
|
|
|
|
2018-03-26 11:47:46 -04:00
|
|
|
update(timeout: timeout, timeout_source: timeout_source)
|
2018-03-20 20:20:15 -04:00
|
|
|
end
|
2018-09-02 10:35:15 -04:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def set_build_project
|
|
|
|
self.project_id ||= self.build.project_id
|
|
|
|
end
|
2018-02-28 21:12:32 -05:00
|
|
|
end
|
|
|
|
end
|