gitlab-org--gitlab-foss/app/models/ci/build_metadata.rb

36 lines
1.1 KiB
Ruby
Raw Normal View History

module Ci
# 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.
class BuildMetadata < ActiveRecord::Base
extend Gitlab::Ci::Model
include Presentable
include ChronicDurationAttribute
self.table_name = 'ci_builds_metadata'
belongs_to :build, class_name: 'Ci::Build'
belongs_to :project
validates :build, presence: true
2018-03-22 12:52:28 -04:00
validates :project, presence: true
2018-03-22 12:52:28 -04:00
chronic_duration_attr_reader :timeout_human_readable, :timeout
enum timeout_source: {
unknown_timeout_source: 1,
project_timeout_source: 2,
runner_timeout_source: 3
}
def update_timeout_state
2018-03-06 10:43:44 -05:00
return unless build.runner.present?
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
update(timeout: timeout, timeout_source: timeout_source)
end
end
end