Commit a98e4081 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Process MWBS in successful pipeline asynchronously

parent a43baa05
......@@ -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|
......
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
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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment