diff options
author | Shinya Maeda <shinya@gitlab.com> | 2017-07-31 23:25:11 +0900 |
---|---|---|
committer | Shinya Maeda <shinya@gitlab.com> | 2017-09-03 23:49:10 +0900 |
commit | e5fd565c74b95815806d139f30676a895b88e29f (patch) | |
tree | 509e871ef3c2eec01a69444750ee636e1317568b /app/services | |
parent | e9924687147b1222fa2df3765a1e3c37662028a2 (diff) | |
download | gitlab-ce-e5fd565c74b95815806d139f30676a895b88e29f.tar.gz |
Solution 1. Persists protected(ref) flag on ci_pipelines table. builds_for_shared_runner and builds_for_specific_runner read the flag instead of executing protected_for? one by one.
Diffstat (limited to 'app/services')
-rw-r--r-- | app/services/ci/create_pipeline_service.rb | 7 | ||||
-rw-r--r-- | app/services/ci/register_job_service.rb | 14 |
2 files changed, 15 insertions, 6 deletions
diff --git a/app/services/ci/create_pipeline_service.rb b/app/services/ci/create_pipeline_service.rb index de2cd7e87be..4b141047bce 100644 --- a/app/services/ci/create_pipeline_service.rb +++ b/app/services/ci/create_pipeline_service.rb @@ -12,7 +12,8 @@ module Ci tag: tag?, trigger_requests: Array(trigger_request), user: current_user, - pipeline_schedule: schedule + pipeline_schedule: schedule, + protected: protected? ) result = validate(current_user, @@ -175,6 +176,10 @@ module Ci origin_sha && origin_sha != Gitlab::Git::BLANK_SHA end + def protected? + project.protected_for?(ref) + end + def error(message, save: false) pipeline.tap do pipeline.errors.add(:base, message) diff --git a/app/services/ci/register_job_service.rb b/app/services/ci/register_job_service.rb index 414f672cc6a..93b1c86aad4 100644 --- a/app/services/ci/register_job_service.rb +++ b/app/services/ci/register_job_service.rb @@ -54,21 +54,25 @@ module Ci private def builds_for_shared_runner - new_builds. + b = new_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('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 # this returns builds that are ordered by number of running builds # we prefer projects that don't use shared runners at all - 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') + b.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') end def builds_for_specific_runner - new_builds.where(project: runner.projects.without_deleted.with_builds_enabled).order('created_at ASC') + b = new_builds.where(project: runner.projects.without_deleted.with_builds_enabled) + b = runner.protected? ? b.on_protected : b.unprotected + b.order('created_at ASC') end def running_builds_for_shared_runners |