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 ...@@ -237,6 +237,12 @@ module Ci
pipeline.run_after_commit do pipeline.run_after_commit do
PipelineHooksWorker.perform_async(pipeline.id) 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) if Feature.enabled?(:expire_job_and_pipeline_cache_synchronously, pipeline.project, default_enabled: :yaml)
Ci::ExpirePipelineCacheService.new.execute(pipeline) # rubocop: disable CodeReuse/ServiceClass Ci::ExpirePipelineCacheService.new.execute(pipeline) # rubocop: disable CodeReuse/ServiceClass
else else
...@@ -276,14 +282,6 @@ module Ci ...@@ -276,14 +282,6 @@ module Ci
end end
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| after_transition any => ::Ci::Pipeline.completed_statuses do |pipeline|
pipeline.run_after_commit do pipeline.run_after_commit do
::Ci::TestFailureHistoryService.new(pipeline).async.perform_if_needed # rubocop: disable CodeReuse/ServiceClass ::Ci::TestFailureHistoryService.new(pipeline).async.perform_if_needed # rubocop: disable CodeReuse/ServiceClass
......
...@@ -119,6 +119,8 @@ class Deployment < ApplicationRecord ...@@ -119,6 +119,8 @@ class Deployment < ApplicationRecord
next if transition.loopback? next if transition.loopback?
deployment.run_after_commit do deployment.run_after_commit do
next unless deployment.project.jira_subscription_exists?
::JiraConnect::SyncDeploymentsWorker.perform_async(id) ::JiraConnect::SyncDeploymentsWorker.perform_async(id)
end end
end end
...@@ -126,6 +128,8 @@ class Deployment < ApplicationRecord ...@@ -126,6 +128,8 @@ class Deployment < ApplicationRecord
after_create unless: :importing? do |deployment| after_create unless: :importing? do |deployment|
run_after_commit do run_after_commit do
next unless deployment.project.jira_subscription_exists?
::JiraConnect::SyncDeploymentsWorker.perform_async(deployment.id) ::JiraConnect::SyncDeploymentsWorker.perform_async(deployment.id)
end end
end end
......
...@@ -43,6 +43,7 @@ module FeatureFlags ...@@ -43,6 +43,7 @@ module FeatureFlags
def sync_to_jira(feature_flag) def sync_to_jira(feature_flag)
return unless feature_flag.present? return unless feature_flag.present?
return unless project.jira_subscription_exists?
seq_id = ::Atlassian::JiraConnect::Client.generate_update_sequence_id seq_id = ::Atlassian::JiraConnect::Client.generate_update_sequence_id
feature_flag.run_after_commit do feature_flag.run_after_commit do
......
...@@ -1358,6 +1358,19 @@ RSpec.describe Ci::Pipeline, :mailer, factory_default: :keep do ...@@ -1358,6 +1358,19 @@ RSpec.describe Ci::Pipeline, :mailer, factory_default: :keep do
describe 'synching status to Jira' do describe 'synching status to Jira' do
let(:worker) { ::JiraConnect::SyncBuildsWorker } let(:worker) { ::JiraConnect::SyncBuildsWorker }
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.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| %i[prepare! run! skip! drop! succeed! cancel! block! delay!].each do |event|
context "when we call pipeline.#{event}" do context "when we call pipeline.#{event}" do
it 'triggers a Jira synch worker' do it 'triggers a Jira synch worker' do
...@@ -1368,6 +1381,7 @@ RSpec.describe Ci::Pipeline, :mailer, factory_default: :keep do ...@@ -1368,6 +1381,7 @@ RSpec.describe Ci::Pipeline, :mailer, factory_default: :keep do
end end
end end
end end
end
describe '#duration', :sidekiq_inline do describe '#duration', :sidekiq_inline do
context 'when multiple builds are finished' do context 'when multiple builds are finished' do
......
...@@ -269,10 +269,24 @@ RSpec.describe Deployment do ...@@ -269,10 +269,24 @@ RSpec.describe Deployment do
end end
describe 'synching status to Jira' do 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 } let(:worker) { ::JiraConnect::SyncDeploymentsWorker }
context 'when Jira Connect subscription does not exist' do
it 'does not call the worker' do
expect(worker).not_to receive(:perform_async)
deployment
end
end
context 'when Jira Connect subscription exists' do
before_all do
create(:jira_connect_subscription, namespace: project.namespace)
end
it 'calls the worker on creation' do it 'calls the worker on creation' do
expect(worker).to receive(:perform_async).with(Integer) expect(worker).to receive(:perform_async).with(Integer)
...@@ -298,6 +312,7 @@ RSpec.describe Deployment do ...@@ -298,6 +312,7 @@ RSpec.describe Deployment do
end end
end end
end end
end
describe '#success?' do describe '#success?' do
subject { deployment.success? } subject { deployment.success? }
......
...@@ -62,11 +62,25 @@ RSpec.describe FeatureFlags::CreateService do ...@@ -62,11 +62,25 @@ RSpec.describe FeatureFlags::CreateService do
expect { subject }.to change { Operations::FeatureFlag.count }.by(1) expect { subject }.to change { Operations::FeatureFlag.count }.by(1)
end end
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
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 it 'syncs the feature flag to Jira' do
expect(::JiraConnect::SyncFeatureFlagsWorker).to receive(:perform_async).with(Integer, Integer) expect(::JiraConnect::SyncFeatureFlagsWorker).to receive(:perform_async).with(Integer, Integer)
subject subject
end end
end
it 'creates audit event' do it 'creates audit event' do
expect { subject }.to change { AuditEvent.count }.by(1) expect { subject }.to change { AuditEvent.count }.by(1)
......
...@@ -27,11 +27,25 @@ RSpec.describe FeatureFlags::UpdateService do ...@@ -27,11 +27,25 @@ RSpec.describe FeatureFlags::UpdateService do
expect(subject[:status]).to eq(:success) expect(subject[:status]).to eq(:success)
end end
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
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 it 'syncs the feature flag to Jira' do
expect(::JiraConnect::SyncFeatureFlagsWorker).to receive(:perform_async).with(Integer, Integer) expect(::JiraConnect::SyncFeatureFlagsWorker).to receive(:perform_async).with(Integer, Integer)
subject subject
end end
end
it 'creates audit event with correct message' do it 'creates audit event with correct message' do
name_was = feature_flag.name name_was = feature_flag.name
......
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