summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToon Claes <toon@gitlab.com>2018-06-26 11:08:24 +0200
committerToon Claes <toon@gitlab.com>2018-06-27 21:43:23 +0200
commitd98e4f88c262263a04aa9d8ce727f7bdc7202f07 (patch)
treea2b501590acdf5b4ee3f4c91bf9acb24184e9d2a
parentf63e234b57e07e2020f9698f48c9515905d4b6a3 (diff)
downloadgitlab-ce-d98e4f88c262263a04aa9d8ce727f7bdc7202f07.tar.gz
Extract EachShardWorker into a concern
-rw-r--r--app/workers/concerns/each_shard_worker.rb36
1 files changed, 36 insertions, 0 deletions
diff --git a/app/workers/concerns/each_shard_worker.rb b/app/workers/concerns/each_shard_worker.rb
new file mode 100644
index 00000000000..f063846427e
--- /dev/null
+++ b/app/workers/concerns/each_shard_worker.rb
@@ -0,0 +1,36 @@
+module EachShardWorker
+ extend ActiveSupport::Concern
+ include ::Gitlab::Utils::StrongMemoize
+
+ HEALTHY_SHARD_CHECKS = [
+ Gitlab::HealthChecks::GitalyCheck
+ ].freeze
+
+ def each_shard
+ eligible_shard_names.each do |shard_name|
+ yield shard_name
+ end
+ end
+
+ # override when you want to filter out some shards
+ def eligible_shard_names
+ healthy_shard_names
+ end
+
+ def healthy_shard_names
+ strong_memoize(:healthy_shard_names) do
+ # For now, we need to perform both Gitaly and direct filesystem checks to ensure
+ # the shard is healthy. We take the intersection of the successful checks
+ # as the healthy shards.
+ healthy_ready_shards.map { |result| result.labels[:shard] }.compact.uniq
+ end
+ end
+
+ def healthy_ready_shards
+ ready_shards.map { |result| result.select(&:success) }.inject(:&)
+ end
+
+ def ready_shards
+ HEALTHY_SHARD_CHECKS.map(&:readiness)
+ end
+end