Process MWBS in successful pipeline asynchronously
This commit is contained in:
parent
a43baa056e
commit
a98e4081d1
3 changed files with 37 additions and 1 deletions
|
@ -71,7 +71,7 @@ module Ci
|
|||
end
|
||||
|
||||
after_transition [:created, :pending, :running] => :success do |pipeline|
|
||||
MergeRequests::MergeWhenBuildSucceedsService.new(pipeline.project, nil).trigger(pipeline)
|
||||
PipelineSuccessWorker.perform_async(pipeline.id)
|
||||
end
|
||||
|
||||
after_transition do |pipeline, transition|
|
||||
|
|
12
app/workers/pipeline_success_worker.rb
Normal file
12
app/workers/pipeline_success_worker.rb
Normal file
|
@ -0,0 +1,12 @@
|
|||
class PipelineSuccessWorker
|
||||
include Sidekiq::Worker
|
||||
sidekiq_options queue: :default
|
||||
|
||||
def perform(pipeline_id)
|
||||
Ci::Pipeline.find_by(id: pipeline_id).try do |pipeline|
|
||||
MergeRequests::MergeWhenBuildSucceedsService
|
||||
.new(pipeline.project, nil)
|
||||
.trigger(pipeline)
|
||||
end
|
||||
end
|
||||
end
|
24
spec/workers/pipeline_success_worker_spec.rb
Normal file
24
spec/workers/pipeline_success_worker_spec.rb
Normal file
|
@ -0,0 +1,24 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe PipelineSuccessWorker do
|
||||
describe '#perform' do
|
||||
context 'when pipeline exists' do
|
||||
let(:pipeline) { create(:ci_pipeline, status: 'success') }
|
||||
|
||||
it 'performs "merge when pipeline succeeds"' do
|
||||
expect_any_instance_of(
|
||||
MergeRequests::MergeWhenBuildSucceedsService
|
||||
).to receive(:trigger)
|
||||
|
||||
described_class.new.perform(pipeline.id)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when pipeline does not exist' do
|
||||
it 'does not raise exception' do
|
||||
expect { described_class.new.perform(123) }
|
||||
.not_to raise_error
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue