diff options
author | Tomasz Maczukin <tomasz@maczukin.pl> | 2018-03-05 17:35:06 +0100 |
---|---|---|
committer | Tomasz Maczukin <tomasz@maczukin.pl> | 2018-03-28 13:57:41 +0200 |
commit | bb64b20a1f7dd831e4c200343b531f9d048c02a8 (patch) | |
tree | 6223c95875e53a235bde1b26f9b06a1776acb1ca /app | |
parent | 9ef86b1b12e80bcc3a6277e2b6a36b793c828489 (diff) | |
download | gitlab-ce-bb64b20a1f7dd831e4c200343b531f9d048c02a8.tar.gz |
Refactorize Ci::Build and Ci::BuildMetadata models
Diffstat (limited to 'app')
-rw-r--r-- | app/models/ci/build.rb | 14 | ||||
-rw-r--r-- | app/models/ci/build_metadata.rb | 16 |
2 files changed, 18 insertions, 12 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index cc29c6150d3..7a12d7a3deb 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -24,7 +24,7 @@ module Ci has_one :job_artifacts_metadata, -> { where(file_type: Ci::JobArtifact.file_types[:metadata]) }, class_name: 'Ci::JobArtifact', inverse_of: :job, foreign_key: :job_id has_one :job_artifacts_trace, -> { where(file_type: Ci::JobArtifact.file_types[:trace]) }, class_name: 'Ci::JobArtifact', inverse_of: :job, foreign_key: :job_id - has_one :metadata, class_name: 'Ci::BuildMetadata' + has_one :build_metadata, class_name: 'Ci::BuildMetadata' # The "environment" field for builds is a String, and is the unexpanded name def persisted_environment @@ -85,10 +85,6 @@ module Ci before_save :ensure_token before_destroy { unscoped_project } - before_create do |build| - build.metadata = Ci::BuildMetadata.new - end - after_create unless: :importing? do |build| run_after_commit { BuildHooksWorker.perform_async(build.id) } end @@ -161,10 +157,14 @@ module Ci end before_transition pending: :running do |build| - build.metadata.save_timeout_state! unless build.metadata.nil? + build.metadata.save_timeout_state! end end + def metadata + self.build_metadata ||= Ci::BuildMetadata.new + end + def detailed_status(current_user) Gitlab::Ci::Status::Build::Factory .new(self, current_user) @@ -242,7 +242,7 @@ module Ci end def timeout - [project.build_timeout, runner&.maximum_job_timeout].compact.min + metadata.used_timeout end def triggered_by?(current_user) diff --git a/app/models/ci/build_metadata.rb b/app/models/ci/build_metadata.rb index 7a1315dfcf9..9043bed86bf 100644 --- a/app/models/ci/build_metadata.rb +++ b/app/models/ci/build_metadata.rb @@ -1,4 +1,6 @@ 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 @@ -11,14 +13,18 @@ module Ci chronic_duration_attr_reader :used_timeout_human_readable, :used_timeout enum timeout_source: { - unknown_timeout_source: nil, - project_timeout_source: 1, - runner_timeout_source: 2 + unknown_timeout_source: 1, + project_timeout_source: 2, + runner_timeout_source: 3 } def save_timeout_state! - self.used_timeout = build.timeout - self.timeout_source = build.timeout < build.project.build_timeout ? :runner_timeout_source : :project_timeout_source + project_timeout = build.project&.build_timeout + timeout = [project_timeout, build.runner&.maximum_job_timeout].compact.min + + self.used_timeout = timeout + self.timeout_source = timeout < project_timeout ? :runner_timeout_source : :project_timeout_source + save! end end |