Commit 0e8fa14e authored by Ash McKenzie's avatar Ash McKenzie

Only backoff for certain types

Don't backoff for uploads, LFS objects or CI job artifacts
parent 22192158
......@@ -4,6 +4,16 @@ module Geo
private
# Cannot utilise backoff because there are no events currently being
# generated for uploads, LFS objects or CI job artifacts so we need to rely
# upon expensive DB queries to be executed in order to determine if there's
# work to do.
#
# Overrides Geo::Scheduler::SchedulerWorker#should_apply_backoff?
def should_apply_backoff?
false
end
def max_capacity
current_node.files_max_capacity
end
......
......@@ -109,6 +109,10 @@ module Geo
(Time.now.utc - start_time) >= run_time
end
def should_apply_backoff?
pending_resources.empty?
end
# rubocop: disable CodeReuse/ActiveRecord
def take_batch(*arrays, batch_size: db_retrieve_batch_size)
interleave(*arrays).uniq.compact.take(batch_size)
......@@ -165,7 +169,7 @@ module Geo
def update_pending_resources
if reload_queue?
@pending_resources = load_pending_resources
set_backoff_time! if @pending_resources.empty?
set_backoff_time! if should_apply_backoff?
end
end
......
......@@ -308,18 +308,8 @@ describe Geo::FileDownloadDispatchWorker, :geo do
context 'backoff time' do
let(:cache_key) { "#{described_class.name.underscore}:skip" }
it 'sets the back off time when there are no pending items' do
expect(Rails.cache).to receive(:write).with(cache_key, true, expires_in: 300.seconds).once
subject.perform
end
it 'does not perform Geo::FileDownloadWorker when the backoff time is set' do
create(:lfs_object, :with_file)
expect(Rails.cache).to receive(:read).with(cache_key).and_return(true)
expect(Geo::FileDownloadWorker).not_to receive(:perform_async)
it 'does not set the back off time when there are no pending items' do
expect(Rails.cache).not_to receive(:write).with(cache_key, true, expires_in: 300.seconds)
subject.perform
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