Commit 5a8dd349 authored by Fabio Pitino's avatar Fabio Pitino

Update MR head pipeline when pipeline event is published

Introduce Gitlab::EventStore to publish and subscribe domain events.
When a pipeline is created an event is published and the MR
domain reacts as subscriber to this event by updating the head
pipeline.

Changelog: changed
parent 1d524906
......@@ -95,13 +95,9 @@ module Ci
.build!
if pipeline.persisted?
if Feature.enabled?(:ci_publish_pipeline_events, pipeline.project, default_enabled: :yaml)
Gitlab::EventStore.publish(
Ci::PipelineCreatedEvent.new(data: { pipeline_id: pipeline.id })
)
else
schedule_head_pipeline_update
end
create_namespace_onboarding_action
else
......@@ -141,12 +137,6 @@ module Ci
commit.try(:id)
end
def schedule_head_pipeline_update
pipeline.all_merge_requests.opened.each do |merge_request|
UpdateHeadPipelineForMergeRequestWorker.perform_async(merge_request.id)
end
end
def create_namespace_onboarding_action
Namespaces::OnboardingPipelineCreatedWorker.perform_async(project.namespace_id)
end
......
---
name: ci_publish_pipeline_events
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/34042
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/336752
milestone: '14.3'
type: development
group: group::pipeline execution
default_enabled: false
......@@ -161,30 +161,6 @@ RSpec.describe Ci::CreatePipelineService do
expect(merge_request_1.reload.head_pipeline).to eq(head_pipeline)
expect(merge_request_2.reload.head_pipeline).to eq(head_pipeline)
end
# TODO: remove after ci_publish_pipeline_events FF is removed
# https://gitlab.com/gitlab-org/gitlab/-/issues/336752
it 'does not schedule sync update for the head pipeline of the merge request' do
expect(UpdateHeadPipelineForMergeRequestWorker)
.not_to receive(:perform_async)
execute_service(ref: 'feature', after: nil)
end
end
context 'when feature flag ci_publish_pipeline_events is disabled' do
before do
stub_feature_flags(ci_publish_pipeline_events: false)
end
it 'schedules update for the head pipeline of the merge request' do
expect(UpdateHeadPipelineForMergeRequestWorker)
.to receive(:perform_async).with(merge_request_1.id)
expect(UpdateHeadPipelineForMergeRequestWorker)
.to receive(:perform_async).with(merge_request_2.id)
execute_service(ref: 'feature', after: nil)
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