Skip to content
代码片段 群组 项目
未验证 提交 aeb47d1f 编辑于 作者: Shubham Kumar's avatar Shubham Kumar 提交者: GitLab
浏览文件

Fix bitbucket spread cal job

Changelog: changed
上级 1c2e2e33
No related branches found
No related tags found
无相关合并请求
......@@ -76,9 +76,14 @@ def mark_as_enqueued(object)
end
def calculate_job_delay(job_index)
multiplier = (job_index / BATCH_SIZE)
runtime = Time.current - job_started_at
multiplier = (job_index / BATCH_SIZE.to_f)
(multiplier * 1.minute) + 1.second
(multiplier * 1.minute) + 1.second - runtime
end
def job_started_at
@job_started_at ||= Time.current
end
end
end
......
......@@ -83,9 +83,14 @@ def mark_as_processed(object)
end
def calculate_job_delay(job_index)
multiplier = (job_index / BATCH_SIZE)
runtime = Time.current - job_started_at
multiplier = (job_index / BATCH_SIZE.to_f)
(multiplier * 1.minute) + 1.second
(multiplier * 1.minute) + 1.second - runtime
end
def job_started_at
@job_started_at ||= Time.current
end
def track_import_failure!(project, exception:, **args)
......
......@@ -46,7 +46,8 @@
end
expect(Gitlab::BitbucketImport::ImportLfsObjectWorker).to receive(:perform_in)
.with(1.second, project.id, lfs_attributes.stringify_keys, start_with(Gitlab::JobWaiter::KEY_PREFIX))
.with(an_instance_of(Float), project.id,
lfs_attributes.stringify_keys, start_with(Gitlab::JobWaiter::KEY_PREFIX))
waiter = importer.execute
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::BitbucketImport::ParallelScheduling, feature_category: :importers do
let_it_be(:project) { build(:project) }
describe '#calculate_job_delay' do
let(:importer_class) do
Class.new do
include Gitlab::BitbucketImport::ParallelScheduling
def collection_method
:issues
end
end
end
let(:importer) { importer_class.new(project) }
before do
stub_const("#{described_class}::BATCH_SIZE", 2)
end
it 'returns an incremental delay', :freeze_time do
expect(importer.send(:calculate_job_delay, 1)).to eq(0.5.minutes + 1.second)
expect(importer.send(:calculate_job_delay, 100)).to eq(50.minutes + 1.second)
end
it 'deducts the runtime from the delay', :freeze_time do
allow(importer).to receive(:job_started_at).and_return(1.second.ago)
expect(importer.send(:calculate_job_delay, 1)).to eq(0.5.minutes)
expect(importer.send(:calculate_job_delay, 100)).to eq(50.minutes)
end
end
end
......@@ -46,7 +46,8 @@
end
expect(Gitlab::BitbucketServerImport::ImportLfsObjectWorker).to receive(:perform_in)
.with(1.second, project.id, lfs_attributes.stringify_keys, start_with(Gitlab::JobWaiter::KEY_PREFIX))
.with(an_instance_of(Float), project.id,
lfs_attributes.stringify_keys, start_with(Gitlab::JobWaiter::KEY_PREFIX))
waiter = importer.execute
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::BitbucketServerImport::ParallelScheduling, feature_category: :importers do
let_it_be(:project) { build(:project) }
describe '#calculate_job_delay' do
let(:importer_class) do
Class.new do
include Gitlab::BitbucketServerImport::ParallelScheduling
def collection_method
:issues
end
end
end
let(:importer) { importer_class.new(project) }
before do
stub_const("#{described_class}::BATCH_SIZE", 2)
end
it 'returns an incremental delay', :freeze_time do
expect(importer.send(:calculate_job_delay, 1)).to eq(0.5.minutes + 1.second)
expect(importer.send(:calculate_job_delay, 100)).to eq(50.minutes + 1.second)
end
it 'deducts the runtime from the delay', :freeze_time do
allow(importer).to receive(:job_started_at).and_return(1.second.ago)
expect(importer.send(:calculate_job_delay, 1)).to eq(0.5.minutes)
expect(importer.send(:calculate_job_delay, 100)).to eq(50.minutes)
end
end
end
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册