Commit 1282e2e5 authored by Nikola Milojevic's avatar Nikola Milojevic Committed by Kamil Trzciński

Delayed scheduling of BuildHooksWorker [RUN ALL RSPEC] [RUN AS-IF-FOSS]

parent dc735579
......@@ -11,6 +11,16 @@ class BuildHooksWorker # rubocop:disable Scalability/IdempotentWorker
urgency :high
data_consistency :delayed, feature_flag: :load_balancing_for_build_hooks_worker
DATA_CONSISTENCY_DELAY = 3
def self.perform_async(*args)
if Feature.enabled?(:delayed_perform_for_build_hooks_worker, default_enabled: :yaml)
perform_in(DATA_CONSISTENCY_DELAY.seconds, *args)
else
super
end
end
# rubocop: disable CodeReuse/ActiveRecord
def perform(build_id)
Ci::Build.includes({ runner: :tags })
......
---
name: delayed_perform_for_build_hooks_worker
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/61149
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/330132
milestone: '13.12'
type: development
group: group::memory
default_enabled: false
......@@ -23,6 +23,24 @@ RSpec.describe BuildHooksWorker do
end
end
describe '.perform_async' do
context 'when delayed_perform_for_build_hooks_worker feature flag is disabled' do
before do
stub_feature_flags(delayed_perform_for_build_hooks_worker: false)
end
it 'does not call perform_in' do
expect(described_class).not_to receive(:perform_in)
end
end
it 'delays scheduling a job by calling perform_in' do
expect(described_class).to receive(:perform_in).with(described_class::DATA_CONSISTENCY_DELAY.second, 123)
described_class.perform_async(123)
end
end
it_behaves_like 'worker with data consistency',
described_class,
feature_flag: :load_balancing_for_build_hooks_worker,
......
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