Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToon Claes <toon@gitlab.com>2018-06-26 16:12:29 +0300
committerToon Claes <toon@gitlab.com>2018-06-27 22:43:23 +0300
commit95ac8b0e1d0385429f5a09edf0dc908346fdd3a7 (patch)
tree78501c423558294caf5a5dc3d31ecb460e3f9d2b /app/workers/repository_check/batch_worker.rb
parent48901bdecfe30fd201c01a608fdc3b35e4f70e08 (diff)
Add RepositoryCheck::DispatchWorker to start worker per shard
The RepositoryCheck::DispatchWorker will start a RepositoryCheck::BatchWorker for each healthy shard. Closes gitlab-org/gitlab-ce#48042
Diffstat (limited to 'app/workers/repository_check/batch_worker.rb')
-rw-r--r--app/workers/repository_check/batch_worker.rb17
1 files changed, 13 insertions, 4 deletions
diff --git a/app/workers/repository_check/batch_worker.rb b/app/workers/repository_check/batch_worker.rb
index 898bca976ec..051382a08a9 100644
--- a/app/workers/repository_check/batch_worker.rb
+++ b/app/workers/repository_check/batch_worker.rb
@@ -3,13 +3,18 @@
module RepositoryCheck
class BatchWorker
include ApplicationWorker
- include CronjobQueue
+ include RepositoryCheckQueue
RUN_TIME = 3600
BATCH_SIZE = 10_000
- def perform
+ attr_reader :shard_name
+
+ def perform(shard_name)
+ @shard_name = shard_name
+
return unless Gitlab::CurrentSettings.repository_checks_enabled
+ return unless Gitlab::ShardHealthCache.healthy_shard?(shard_name)
start = Time.now
@@ -39,18 +44,22 @@ module RepositoryCheck
end
def never_checked_project_ids(batch_size)
- Project.where(last_repository_check_at: nil)
+ projects_on_shard.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.not(last_repository_check_at: nil)
+ projects_on_shard.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
+ def projects_on_shard
+ Project.where(repository_storage: shard_name)
+ end
+
def try_obtain_lease(id)
# Use a 24-hour timeout because on servers/projects where 'git fsck' is
# super slow we definitely do not want to run it twice in parallel.