Commit fd52c435 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Only enqueue Jira workers when configured

This skips enqueuing of Jira Connect workers when the integration is not
setup for the project. Most of the time the integration isn't setup so
this saves us a lot of Sidekiq job processing overhead.

Changelog: performance
parent 890b936f
......@@ -237,6 +237,12 @@ module Ci
pipeline.run_after_commit do
PipelineHooksWorker.perform_async(pipeline.id)
if pipeline.project.jira_subscription_exists?
# Passing the seq-id ensures this is idempotent
seq_id = ::Atlassian::JiraConnect::Client.generate_update_sequence_id
::JiraConnect::SyncBuildsWorker.perform_async(pipeline.id, seq_id)
end
if Feature.enabled?(:expire_job_and_pipeline_cache_synchronously, pipeline.project, default_enabled: :yaml)
Ci::ExpirePipelineCacheService.new.execute(pipeline) # rubocop: disable CodeReuse/ServiceClass
else
......@@ -276,14 +282,6 @@ module Ci
end
end
after_transition any => any do |pipeline|
pipeline.run_after_commit do
# Passing the seq-id ensures this is idempotent
seq_id = ::Atlassian::JiraConnect::Client.generate_update_sequence_id
::JiraConnect::SyncBuildsWorker.perform_async(pipeline.id, seq_id)
end
end
after_transition any => ::Ci::Pipeline.completed_statuses do |pipeline|
pipeline.run_after_commit do
::Ci::TestFailureHistoryService.new(pipeline).async.perform_if_needed # rubocop: disable CodeReuse/ServiceClass
......
......@@ -119,6 +119,8 @@ class Deployment < ApplicationRecord
next if transition.loopback?
deployment.run_after_commit do
next unless deployment.project.jira_subscription_exists?
::JiraConnect::SyncDeploymentsWorker.perform_async(id)
end
end
......@@ -126,6 +128,8 @@ class Deployment < ApplicationRecord
after_create unless: :importing? do |deployment|
run_after_commit do
next unless deployment.project.jira_subscription_exists?
::JiraConnect::SyncDeploymentsWorker.perform_async(deployment.id)
end
end
......
......@@ -43,6 +43,7 @@ module FeatureFlags
def sync_to_jira(feature_flag)
return unless feature_flag.present?
return unless project.jira_subscription_exists?
seq_id = ::Atlassian::JiraConnect::Client.generate_update_sequence_id
feature_flag.run_after_commit do
......
......@@ -1358,12 +1358,26 @@ RSpec.describe Ci::Pipeline, :mailer, factory_default: :keep do
describe 'synching status to Jira' do
let(:worker) { ::JiraConnect::SyncBuildsWorker }
%i[prepare! run! skip! drop! succeed! cancel! block! delay!].each do |event|
context "when we call pipeline.#{event}" do
it 'triggers a Jira synch worker' do
expect(worker).to receive(:perform_async).with(pipeline.id, Integer)
context 'when Jira Connect subscription does not exist' do
it 'does not trigger a Jira synch worker' do
expect(worker).not_to receive(:perform_async)
pipeline.send(event)
pipeline.prepare!
end
end
context 'when Jira Connect subscription exists' do
before_all do
create(:jira_connect_subscription, namespace: project.namespace)
end
%i[prepare! run! skip! drop! succeed! cancel! block! delay!].each do |event|
context "when we call pipeline.#{event}" do
it 'triggers a Jira synch worker' do
expect(worker).to receive(:perform_async).with(pipeline.id, Integer)
pipeline.send(event)
end
end
end
end
......
......@@ -269,30 +269,45 @@ RSpec.describe Deployment do
end
describe 'synching status to Jira' do
let(:deployment) { create(:deployment) }
let_it_be(:project) { create(:project, :repository) }
let(:deployment) { create(:deployment, project: project) }
let(:worker) { ::JiraConnect::SyncDeploymentsWorker }
it 'calls the worker on creation' do
expect(worker).to receive(:perform_async).with(Integer)
context 'when Jira Connect subscription does not exist' do
it 'does not call the worker' do
expect(worker).not_to receive(:perform_async)
deployment
deployment
end
end
it 'does not call the worker for skipped deployments' do
expect(deployment).to be_present # warm-up, ignore the creation trigger
context 'when Jira Connect subscription exists' do
before_all do
create(:jira_connect_subscription, namespace: project.namespace)
end
expect(worker).not_to receive(:perform_async)
it 'calls the worker on creation' do
expect(worker).to receive(:perform_async).with(Integer)
deployment.skip!
end
deployment
end
it 'does not call the worker for skipped deployments' do
expect(deployment).to be_present # warm-up, ignore the creation trigger
expect(worker).not_to receive(:perform_async)
deployment.skip!
end
%i[run! succeed! drop! cancel!].each do |event|
context "when we call pipeline.#{event}" do
it 'triggers a Jira synch worker' do
expect(worker).to receive(:perform_async).with(deployment.id)
%i[run! succeed! drop! cancel!].each do |event|
context "when we call pipeline.#{event}" do
it 'triggers a Jira synch worker' do
expect(worker).to receive(:perform_async).with(deployment.id)
deployment.send(event)
deployment.send(event)
end
end
end
end
......
......@@ -62,10 +62,24 @@ RSpec.describe FeatureFlags::CreateService do
expect { subject }.to change { Operations::FeatureFlag.count }.by(1)
end
it 'syncs the feature flag to Jira' do
expect(::JiraConnect::SyncFeatureFlagsWorker).to receive(:perform_async).with(Integer, Integer)
context 'when Jira Connect subscription does not exist' do
it 'does not sync the feature flag to Jira' do
expect(::JiraConnect::SyncFeatureFlagsWorker).not_to receive(:perform_async)
subject
subject
end
end
context 'when Jira Connect subscription exists' do
before do
create(:jira_connect_subscription, namespace: project.namespace)
end
it 'syncs the feature flag to Jira' do
expect(::JiraConnect::SyncFeatureFlagsWorker).to receive(:perform_async).with(Integer, Integer)
subject
end
end
it 'creates audit event' do
......
......@@ -27,10 +27,24 @@ RSpec.describe FeatureFlags::UpdateService do
expect(subject[:status]).to eq(:success)
end
it 'syncs the feature flag to Jira' do
expect(::JiraConnect::SyncFeatureFlagsWorker).to receive(:perform_async).with(Integer, Integer)
context 'when Jira Connect subscription does not exist' do
it 'does not sync the feature flag to Jira' do
expect(::JiraConnect::SyncFeatureFlagsWorker).not_to receive(:perform_async)
subject
end
end
subject
context 'when Jira Connect subscription exists' do
before do
create(:jira_connect_subscription, namespace: project.namespace)
end
it 'syncs the feature flag to Jira' do
expect(::JiraConnect::SyncFeatureFlagsWorker).to receive(:perform_async).with(Integer, Integer)
subject
end
end
it 'creates audit event with correct message' do
......
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