Commit 0968e6ad authored by Shinya Maeda's avatar Shinya Maeda

Tweak only new_builds. Revert the rest.

parent e5fd565c
...@@ -40,11 +40,6 @@ module Ci ...@@ -40,11 +40,6 @@ module Ci
.where('ci_pipelines.protected IS TRUE') .where('ci_pipelines.protected IS TRUE')
end end
scope :unprotected, ->() do
joins("LEFT JOIN ci_pipelines ON ci_builds.commit_id = ci_pipelines.id")
.where('ci_pipelines.protected IS FALSE')
end
mount_uploader :artifacts_file, ArtifactUploader mount_uploader :artifacts_file, ArtifactUploader
mount_uploader :artifacts_metadata, ArtifactUploader mount_uploader :artifacts_metadata, ArtifactUploader
......
...@@ -54,25 +54,21 @@ module Ci ...@@ -54,25 +54,21 @@ module Ci
private private
def builds_for_shared_runner def builds_for_shared_runner
b = new_builds. new_builds.
# don't run projects which have not enabled shared runners and builds # don't run projects which have not enabled shared runners and builds
joins(:project).where(projects: { shared_runners_enabled: true, pending_delete: false }) joins(:project).where(projects: { shared_runners_enabled: true, pending_delete: false })
.joins('LEFT JOIN project_features ON ci_builds.project_id = project_features.project_id') .joins('LEFT JOIN project_features ON ci_builds.project_id = project_features.project_id')
.where('project_features.builds_access_level IS NULL or project_features.builds_access_level > 0') .where('project_features.builds_access_level IS NULL or project_features.builds_access_level > 0').
b = runner.protected? ? b.on_protected : b.unprotected
# Implement fair scheduling # Implement fair scheduling
# this returns builds that are ordered by number of running builds # this returns builds that are ordered by number of running builds
# we prefer projects that don't use shared runners at all # we prefer projects that don't use shared runners at all
b.joins("LEFT JOIN (#{running_builds_for_shared_runners.to_sql}) AS project_builds ON ci_builds.project_id=project_builds.project_id") joins("LEFT JOIN (#{running_builds_for_shared_runners.to_sql}) AS project_builds ON ci_builds.project_id=project_builds.project_id")
.order('COALESCE(project_builds.running_builds, 0) ASC', 'ci_builds.id ASC') .order('COALESCE(project_builds.running_builds, 0) ASC', 'ci_builds.id ASC')
end end
def builds_for_specific_runner def builds_for_specific_runner
b = new_builds.where(project: runner.projects.without_deleted.with_builds_enabled) new_builds.where(project: runner.projects.without_deleted.with_builds_enabled).order('created_at ASC')
b = runner.protected? ? b.on_protected : b.unprotected
b.order('created_at ASC')
end end
def running_builds_for_shared_runners def running_builds_for_shared_runners
...@@ -81,7 +77,9 @@ module Ci ...@@ -81,7 +77,9 @@ module Ci
end end
def new_builds def new_builds
Ci::Build.pending.unstarted builds = Ci::Build.pending.unstarted
builds = builds.on_protected if runner.protected?
builds
end end
def shared_runner_build_limits_feature_enabled? def shared_runner_build_limits_feature_enabled?
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment