2018-07-21 20:39:30 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-06-26 05:08:24 -04:00
|
|
|
module EachShardWorker
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
include ::Gitlab::Utils::StrongMemoize
|
|
|
|
|
2018-06-27 10:42:17 -04:00
|
|
|
def each_eligible_shard
|
2018-06-26 08:27:01 -04:00
|
|
|
Gitlab::ShardHealthCache.update(eligible_shard_names)
|
|
|
|
|
2018-06-26 05:08:24 -04:00
|
|
|
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
|
2018-06-27 15:02:32 -04:00
|
|
|
healthy_ready_shards.map { |result| result.labels[:shard] }
|
2018-06-26 05:08:24 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def healthy_ready_shards
|
2018-06-27 15:02:32 -04:00
|
|
|
ready_shards.select(&:success)
|
2018-06-26 05:08:24 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def ready_shards
|
2018-06-27 15:02:32 -04:00
|
|
|
Gitlab::HealthChecks::GitalyCheck.readiness
|
2018-06-26 05:08:24 -04:00
|
|
|
end
|
|
|
|
end
|