Skip to content
代码片段 群组 项目
提交 76151659 编辑于 作者: Dmitry Gruzd's avatar Dmitry Gruzd
浏览文件

Merge branch '367334-don-t-raise-an-exception-when-the-batch_size-is-1' into 'master'

Resolve "Don't raise an exception when the batch_size is 1"

See merge request gitlab-org/gitlab!92101
No related branches found
No related tags found
无相关合并请求
......@@ -112,7 +112,7 @@ def time_efficiency
end
def can_split?(exception)
attempts >= MAX_ATTEMPTS && TIMEOUT_EXCEPTIONS.include?(exception&.class) && batch_size > sub_batch_size
attempts >= MAX_ATTEMPTS && TIMEOUT_EXCEPTIONS.include?(exception&.class) && batch_size > sub_batch_size && batch_size > 1
end
def split_and_retry!
......@@ -121,7 +121,7 @@ def split_and_retry!
new_batch_size = batch_size / 2
raise SplitAndRetryError, 'Job cannot be split further' if new_batch_size < 1
break update!(attempts: 0) if new_batch_size < 1
batching_strategy = batched_migration.batch_class.new(connection: self.class.connection)
next_batch_bounds = batching_strategy.next_batch(
......
......@@ -304,6 +304,13 @@
it { expect(subject).to be_falsey }
end
context 'when the batch_size is 1' do
let(:job) { create(:batched_background_migration_job, :failed, batch_size: 1) }
let(:exception) { ActiveRecord::StatementTimeout.new }
it { expect(subject).to be_falsey }
end
end
describe '#time_efficiency' do
......@@ -415,10 +422,18 @@
end
context 'when batch size is already 1' do
let!(:job) { create(:batched_background_migration_job, :failed, batch_size: 1) }
let!(:job) { create(:batched_background_migration_job, :failed, batch_size: 1, attempts: 3) }
it 'raises an exception' do
expect { job.split_and_retry! }.to raise_error 'Job cannot be split further'
it 'keeps the same batch size' do
job.split_and_retry!
expect(job.reload.batch_size).to eq 1
end
it 'resets the number of attempts' do
job.split_and_retry!
expect(job.attempts).to eq 0
end
end
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册