debian-mirror-gitlab/app/models/ci/build_metadata.rb

48 lines
1.4 KiB
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
2018-05-09 12:01:36 +05:30
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'
2019-03-02 22:35:43 +05:30
belongs_to :build, class_name: 'CommitStatus'
2018-05-09 12:01:36 +05:30
belongs_to :project
2019-02-15 15:39:39 +05:30
before_create :set_build_project
2018-05-09 12:01:36 +05:30
validates :build, presence: true
2019-02-15 15:39:39 +05:30
serialize :config_options, Serializers::JSON # rubocop:disable Cop/ActiveRecordSerialize
serialize :config_variables, Serializers::JSON # rubocop:disable Cop/ActiveRecordSerialize
2018-05-09 12:01:36 +05:30
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
return unless build.runner.present?
project_timeout = project&.build_timeout
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
2019-02-15 15:39:39 +05:30
private
def set_build_project
self.project_id ||= self.build.project_id
end
2018-05-09 12:01:36 +05:30
end
end