summaryrefslogtreecommitdiff
path: root/app/models/ci
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-02-14 12:09:03 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-02-14 12:09:03 +0000
commit5366964a10484c2783a646b35a6da9eece01b242 (patch)
tree4a5a7a289d44e63d96a50a6a64db6e16b871f19c /app/models/ci
parent733befe96ad19f5a02e442c4a9cc8059d3aabbda (diff)
downloadgitlab-ce-5366964a10484c2783a646b35a6da9eece01b242.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models/ci')
-rw-r--r--app/models/ci/build.rb2
-rw-r--r--app/models/ci/processable.rb29
2 files changed, 30 insertions, 1 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb
index b0502f7a26e..27a394e4ab8 100644
--- a/app/models/ci/build.rb
+++ b/app/models/ci/build.rb
@@ -818,7 +818,7 @@ module Ci
depended_jobs = depends_on_builds
# find all jobs that are needed
- if Feature.enabled?(:ci_dag_support, project, default_enabled: true) && needs.exists?
+ if Feature.enabled?(:ci_dag_support, project, default_enabled: true) && scheduling_type_dag?
depended_jobs = depended_jobs.where(name: needs.artifacts.select(:name))
end
diff --git a/app/models/ci/processable.rb b/app/models/ci/processable.rb
index 95fb75688a9..6c080582cae 100644
--- a/app/models/ci/processable.rb
+++ b/app/models/ci/processable.rb
@@ -12,6 +12,18 @@ module Ci
scope :preload_needs, -> { preload(:needs) }
+ scope :with_needs, -> (names = nil) do
+ needs = Ci::BuildNeed.scoped_build.select(1)
+ needs = needs.where(name: names) if names
+ where('EXISTS (?)', needs).preload(:needs)
+ end
+
+ scope :without_needs, -> (names = nil) do
+ needs = Ci::BuildNeed.scoped_build.select(1)
+ needs = needs.where(name: names) if names
+ where('NOT EXISTS (?)', needs)
+ end
+
def self.select_with_aggregated_needs(project)
return all unless Feature.enabled?(:ci_dag_support, project, default_enabled: true)
@@ -26,6 +38,18 @@ module Ci
)
end
+ # Old processables may have scheduling_type as nil,
+ # so we need to ensure the data exists before using it.
+ def self.populate_scheduling_type!
+ needs = Ci::BuildNeed.scoped_build.select(1)
+ where(scheduling_type: nil).update_all(
+ "scheduling_type = CASE WHEN (EXISTS (#{needs.to_sql}))
+ THEN #{scheduling_types[:dag]}
+ ELSE #{scheduling_types[:stage]}
+ END"
+ )
+ end
+
validates :type, presence: true
validates :scheduling_type, presence: true, on: :create, if: :validate_scheduling_type?
@@ -53,6 +77,11 @@ module Ci
raise NotImplementedError
end
+ # Overriding scheduling_type enum's method for nil `scheduling_type`s
+ def scheduling_type_dag?
+ super || find_legacy_scheduling_type == :dag
+ end
+
# scheduling_type column of previous builds/bridges have not been populated,
# so we calculate this value on runtime when we need it.
def find_legacy_scheduling_type