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

each_shard_worker.rb « concerns « workers « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d1d558f55fed3dcb7bbcd3b20cfd2c4e2dd261a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# frozen_string_literal: true

module EachShardWorker
  extend ActiveSupport::Concern
  include ::Gitlab::Utils::StrongMemoize

  def each_eligible_shard
    Gitlab::ShardHealthCache.update(eligible_shard_names)

    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
      healthy_ready_shards.map { |result| result.labels[:shard] }
    end
  end

  def healthy_ready_shards
    success_checks, failed_checks = ready_shards.partition(&:success)

    if failed_checks.any?
      ::Gitlab::AppLogger.error(message: 'Excluding unhealthy shards', failed_checks: failed_checks.map(&:payload), class: self.class.name)
    end

    success_checks
  end

  def ready_shards
    Gitlab::HealthChecks::GitalyCheck.readiness
  end
end