Commit 6f6d2d0a authored by Jacob Vosmaer's avatar Jacob Vosmaer

Use more conservative limits

parent bf31b449
......@@ -35,7 +35,7 @@ module RepositoryCheck
limit = 10_000
never_checked_projects = Project.where('last_repository_check_at IS NULL').limit(limit).
pluck(:id)
old_check_projects = Project.where('last_repository_check_at < ?', 1.week.ago).
old_check_projects = Project.where('last_repository_check_at < ?', 1.month.ago).
reorder('last_repository_check_at ASC').limit(limit).pluck(:id)
never_checked_projects + old_check_projects
end
......
......@@ -5,8 +5,8 @@ module RepositoryCheck
sidekiq_options retry: false
def perform
# Do batched updates because these updates will be slow and locking
Project.select(:id).find_in_batches(batch_size: 1000) do |batch|
# Do small batched updates because these updates will be slow and locking
Project.select(:id).find_in_batches(batch_size: 100) do |batch|
Project.where(id: batch.map(&:id)).update_all(
last_repository_check_failed: nil,
last_repository_check_at: nil,
......
......@@ -5,17 +5,17 @@ describe RepositoryCheck::BatchWorker do
it 'prefers projects that have never been checked' do
projects = create_list(:project, 3)
projects[0].update_column(:last_repository_check_at, 1.month.ago)
projects[2].update_column(:last_repository_check_at, 3.weeks.ago)
projects[0].update_column(:last_repository_check_at, 4.months.ago)
projects[2].update_column(:last_repository_check_at, 3.months.ago)
expect(subject.perform).to eq(projects.values_at(1, 0, 2).map(&:id))
end
it 'sorts projects by last_repository_check_at' do
projects = create_list(:project, 3)
projects[0].update_column(:last_repository_check_at, 2.weeks.ago)
projects[1].update_column(:last_repository_check_at, 1.month.ago)
projects[2].update_column(:last_repository_check_at, 3.weeks.ago)
projects[0].update_column(:last_repository_check_at, 2.months.ago)
projects[1].update_column(:last_repository_check_at, 4.months.ago)
projects[2].update_column(:last_repository_check_at, 3.months.ago)
expect(subject.perform).to eq(projects.values_at(1, 2, 0).map(&:id))
end
......@@ -23,7 +23,7 @@ describe RepositoryCheck::BatchWorker do
it 'excludes projects that were checked recently' do
projects = create_list(:project, 3)
projects[0].update_column(:last_repository_check_at, 2.days.ago)
projects[1].update_column(:last_repository_check_at, 1.month.ago)
projects[1].update_column(:last_repository_check_at, 2.months.ago)
projects[2].update_column(:last_repository_check_at, 3.days.ago)
expect(subject.perform).to eq([projects[1].id])
......
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