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,12 +1358,26 @@ RSpec.describe Ci::Pipeline, :mailer, factory_default: :keep do ...@@ -1358,12 +1358,26 @@ 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 }
%i[prepare! run! skip! drop! succeed! cancel! block! delay!].each do |event| context 'when Jira Connect subscription does not exist' do
context "when we call pipeline.#{event}" do it 'does not trigger a Jira synch worker' do
it 'triggers a Jira synch worker' do expect(worker).not_to receive(:perform_async)
expect(worker).to receive(:perform_async).with(pipeline.id, Integer)
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 end
end end
......
...@@ -269,30 +269,45 @@ RSpec.describe Deployment do ...@@ -269,30 +269,45 @@ 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 }
it 'calls the worker on creation' do context 'when Jira Connect subscription does not exist' do
expect(worker).to receive(:perform_async).with(Integer) it 'does not call the worker' do
expect(worker).not_to receive(:perform_async)
deployment deployment
end
end end
it 'does not call the worker for skipped deployments' do context 'when Jira Connect subscription exists' do
expect(deployment).to be_present # warm-up, ignore the creation trigger 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! deployment
end 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| %i[run! succeed! drop! cancel!].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
expect(worker).to receive(:perform_async).with(deployment.id) expect(worker).to receive(:perform_async).with(deployment.id)
deployment.send(event) deployment.send(event)
end
end end
end end
end end
......
...@@ -62,10 +62,24 @@ RSpec.describe FeatureFlags::CreateService do ...@@ -62,10 +62,24 @@ 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
it 'syncs the feature flag to Jira' do context 'when Jira Connect subscription does not exist' do
expect(::JiraConnect::SyncFeatureFlagsWorker).to receive(:perform_async).with(Integer, Integer) 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 end
it 'creates audit event' do it 'creates audit event' do
......
...@@ -27,10 +27,24 @@ RSpec.describe FeatureFlags::UpdateService do ...@@ -27,10 +27,24 @@ RSpec.describe FeatureFlags::UpdateService do
expect(subject[:status]).to eq(:success) expect(subject[:status]).to eq(:success)
end end
it 'syncs the feature flag to Jira' do context 'when Jira Connect subscription does not exist' do
expect(::JiraConnect::SyncFeatureFlagsWorker).to receive(:perform_async).with(Integer, Integer) 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 end
it 'creates audit event with correct message' do 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