Process MWBS in successful pipeline asynchronously

This commit is contained in:
Grzegorz Bizon 2016-10-07 09:32:29 +02:00
parent a43baa056e
commit a98e4081d1
3 changed files with 37 additions and 1 deletions

View file

@ -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|

View 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

View 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