diff options
author | Kamil Trzciński <ayufan@ayufan.eu> | 2019-08-02 20:31:01 +0300 |
---|---|---|
committer | Kamil Trzciński <ayufan@ayufan.eu> | 2019-08-02 21:31:17 +0300 |
commit | 593490e5ac6ec5a92fdcc9b82eebbb455ea6cf48 (patch) | |
tree | 56dd0ba4cbb8876e96cfab57a22c186e3fff418d /app | |
parent | 8156e77c1a25bc6050e5036fa3bbfd29201a6d5c (diff) |
Extend PipelineProcessWorker to accept a list of builds
This changes used worker from `BuildProcessWorker`
to `PipelineProcessWorker` to make pipeline
processing much simpler. We process `pipeline_id`,
based on some triggers.
Diffstat (limited to 'app')
-rw-r--r-- | app/models/ci/pipeline.rb | 4 | ||||
-rw-r--r-- | app/models/commit_status.rb | 2 | ||||
-rw-r--r-- | app/services/ci/process_pipeline_service.rb | 16 | ||||
-rw-r--r-- | app/workers/build_process_worker.rb | 2 | ||||
-rw-r--r-- | app/workers/pipeline_process_worker.rb | 7 |
5 files changed, 19 insertions, 12 deletions
diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index 3515f0b83ee..217061c6814 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -611,8 +611,8 @@ module Ci end # rubocop: disable CodeReuse/ServiceClass - def process!(trigger_build_name = nil) - Ci::ProcessPipelineService.new(project, user).execute(self, trigger_build_name) + def process!(trigger_build_ids = nil) + Ci::ProcessPipelineService.new(project, user).execute(self, trigger_build_ids) end # rubocop: enable CodeReuse/ServiceClass diff --git a/app/models/commit_status.rb b/app/models/commit_status.rb index d7eb78db5b8..004ff037558 100644 --- a/app/models/commit_status.rb +++ b/app/models/commit_status.rb @@ -122,7 +122,7 @@ class CommitStatus < ApplicationRecord commit_status.run_after_commit do if pipeline_id if complete? || manual? - BuildProcessWorker.perform_async(id) + PipelineProcessWorker.perform_async(pipeline_id, [id]) else PipelineUpdateWorker.perform_async(pipeline_id) end diff --git a/app/services/ci/process_pipeline_service.rb b/app/services/ci/process_pipeline_service.rb index e46615bcf75..184d5321020 100644 --- a/app/services/ci/process_pipeline_service.rb +++ b/app/services/ci/process_pipeline_service.rb @@ -4,7 +4,7 @@ module Ci class ProcessPipelineService < BaseService attr_reader :pipeline - def execute(pipeline, trigger_build_name = nil) + def execute(pipeline, trigger_build_ids = nil) @pipeline = pipeline update_retried @@ -16,7 +16,7 @@ module Ci # we evaluate dependent needs, # only when the another job has finished - success = process_builds_with_needs(trigger_build_name) || success + success = process_builds_with_needs(trigger_build_ids) || success @pipeline.update_status @@ -40,12 +40,18 @@ module Ci end end - def process_builds_with_needs(trigger_build_name) - return false unless trigger_build_name + def process_builds_with_needs(trigger_build_ids) + return false unless trigger_build_ids.present? return false unless Feature.enabled?(:ci_dag_support, project) + # rubocop: disable CodeReuse/ActiveRecord + trigger_build_names = pipeline.statuses + .where(id: trigger_build_ids) + .select(:name) + # rubocop: enable CodeReuse/ActiveRecord + created_processables - .with_needs(trigger_build_name) + .with_needs(trigger_build_names) .find_each .map(&method(:process_build_with_needs)) .any? diff --git a/app/workers/build_process_worker.rb b/app/workers/build_process_worker.rb index 19e590ee1d7..9cd9519df1f 100644 --- a/app/workers/build_process_worker.rb +++ b/app/workers/build_process_worker.rb @@ -9,7 +9,7 @@ class BuildProcessWorker # rubocop: disable CodeReuse/ActiveRecord def perform(build_id) CommitStatus.find_by(id: build_id).try do |build| - build.pipeline.process!(build.name) + build.pipeline.process!([build_id]) end end # rubocop: enable CodeReuse/ActiveRecord diff --git a/app/workers/pipeline_process_worker.rb b/app/workers/pipeline_process_worker.rb index f2aa17acb51..96524d93f8d 100644 --- a/app/workers/pipeline_process_worker.rb +++ b/app/workers/pipeline_process_worker.rb @@ -7,9 +7,10 @@ class PipelineProcessWorker queue_namespace :pipeline_processing # rubocop: disable CodeReuse/ActiveRecord - def perform(pipeline_id) - Ci::Pipeline.find_by(id: pipeline_id) - .try(:process!) + def perform(pipeline_id, build_ids = nil) + Ci::Pipeline.find_by(id: pipeline_id).try do |pipeline| + pipeline.process!(build_ids) + end end # rubocop: enable CodeReuse/ActiveRecord end |