diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-19 12:08:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-19 12:08:42 +0300 |
commit | b76ae638462ab0f673e5915986070518dd3f9ad3 (patch) | |
tree | bdab0533383b52873be0ec0eb4d3c66598ff8b91 /app/services/ci/pipelines/add_job_service.rb | |
parent | 434373eabe7b4be9593d18a585fb763f1e5f1a6f (diff) |
Add latest changes from gitlab-org/gitlab@14-2-stable-eev14.2.0-rc42
Diffstat (limited to 'app/services/ci/pipelines/add_job_service.rb')
-rw-r--r-- | app/services/ci/pipelines/add_job_service.rb | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/app/services/ci/pipelines/add_job_service.rb b/app/services/ci/pipelines/add_job_service.rb index 03bdb491200..41f9903e48c 100644 --- a/app/services/ci/pipelines/add_job_service.rb +++ b/app/services/ci/pipelines/add_job_service.rb @@ -3,21 +3,33 @@ module Ci module Pipelines class AddJobService + include ::Gitlab::ExclusiveLeaseHelpers + attr_reader :pipeline def initialize(pipeline) @pipeline = pipeline - raise ArgumentError, "Pipeline must be persisted for this service to be used" unless @pipeline.persisted? + raise ArgumentError, "Pipeline must be persisted for this service to be used" unless pipeline.persisted? end def execute!(job, &block) assign_pipeline_attributes(job) - Ci::Pipeline.transaction do - yield(job) + if Feature.enabled?(:ci_pipeline_add_job_with_lock, pipeline.project, default_enabled: :yaml) + in_lock("ci:pipelines:#{pipeline.id}:add-job", ttl: LOCK_TIMEOUT, sleep_sec: LOCK_SLEEP, retries: LOCK_RETRIES) do + Ci::Pipeline.transaction do + yield(job) + + job.update_older_statuses_retried! if Feature.enabled?(:ci_fix_commit_status_retried, pipeline.project, default_enabled: :yaml) + end + end + else + Ci::Pipeline.transaction do + yield(job) - job.update_older_statuses_retried! if Feature.enabled?(:ci_fix_commit_status_retried, @pipeline.project, default_enabled: :yaml) + job.update_older_statuses_retried! if Feature.enabled?(:ci_fix_commit_status_retried, pipeline.project, default_enabled: :yaml) + end end ServiceResponse.success(payload: { job: job }) @@ -27,10 +39,14 @@ module Ci private + LOCK_TIMEOUT = 1.minute + LOCK_SLEEP = 0.5.seconds + LOCK_RETRIES = 20 + def assign_pipeline_attributes(job) - job.pipeline = @pipeline - job.project = @pipeline.project - job.ref = @pipeline.ref + job.pipeline = pipeline + job.project = pipeline.project + job.ref = pipeline.ref end end end |