Commit 3066de95 authored by Toon Claes's avatar Toon Claes

Rename methods to make it more clear what they do

parent 0bfc2b14
......@@ -16,7 +16,7 @@ module RepositoryCheck
# projects to check. By default sidekiq-cron will start a new
# RepositoryCheckWorker each hour so that as long as there are repositories to
# check, only one (or two) will be checked at a time.
find_batch.each do |project_id|
project_ids.each do |project_id|
break if Time.now - start >= RUN_TIME
next unless try_obtain_lease(project_id)
......@@ -32,7 +32,7 @@ module RepositoryCheck
# array of ID's. This is OK because we do it only once an hour, because
# getting ID's from Postgres is not terribly slow, and because no user
# has to sit and wait for this query to finish.
def find_batch(batch_size = BATCH_SIZE)
def project_ids(batch_size = BATCH_SIZE)
project_ids = never_checked_project_ids(batch_size)
remaining_capacity = batch_size - project_ids.count
......@@ -45,12 +45,14 @@ module RepositoryCheck
end
def never_checked_project_ids(batch_size)
Project.where('last_repository_check_at IS NULL AND created_at < ?', 24.hours.ago)
Project.where(last_repository_check_at: nil)
.where('created_at < ?', 24.hours.ago)
.limit(batch_size).pluck(:id)
end
def old_checked_project_ids(batch_size)
Project.where('last_repository_check_at < ?', 1.month.ago)
Project.where.not(last_repository_check_at: nil)
.where('last_repository_check_at < ?', 1.month.ago)
.reorder(last_repository_check_at: :asc)
.limit(batch_size).pluck(:id)
end
......
......@@ -5,31 +5,31 @@ module RepositoryCheck
def perform(project_id)
project = Project.find(project_id)
result = check(project)
healthy = project_healthy?(project)
save_result(project, result)
update_repository_check_status(project, healthy)
end
private
def save_result(project, result)
def update_repository_check_status(project, healthy)
project.update_columns(
last_repository_check_failed: !result,
last_repository_check_failed: !healthy,
last_repository_check_at: Time.now
)
end
def check(project)
check_repo(project) && check_wiki_repo(project)
def project_healthy?(project)
repo_healthy?(project) && wiki_repo_healthy?(project)
end
def check_repo(project)
def repo_healthy?(project)
return true if project.empty_repo?
git_fsck(project.repository)
end
def check_wiki_repo(project)
def wiki_repo_healthy?(project)
return true unless project.wiki_enabled?
# Historically some projects never had their wiki repos initialized;
......
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