summaryrefslogtreecommitdiff
path: root/lib/gitlab/git/storage/null_circuit_breaker.rb
blob: 261c936c689b6cd29c1a3c9744fd09909de9c751 (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
40
41
42
43
44
45
46
47
48
49
50
module Gitlab
  module Git
    module Storage
      class NullCircuitBreaker
        include CircuitBreakerSettings

        # These will have actual values
        attr_reader :storage,
                    :hostname

        # These will always have nil values
        attr_reader :storage_path

        delegate :last_failure, :failure_count, :no_failures?,
                 to: :failure_info

        def initialize(storage, hostname, error: nil)
          @storage = storage
          @hostname = hostname
          @error = error
        end

        def perform
          @error ? raise(@error) : yield
        end

        def circuit_broken?
          !!@error
        end

        def backing_off?
          false
        end

        def failure_info
          @failure_info ||=
            if circuit_broken?
              Gitlab::Git::Storage::FailureInfo.new(Time.now,
                                                    Time.now,
                                                    failure_count_threshold)
            else
              Gitlab::Git::Storage::FailureInfo.new(nil,
                                                    nil,
                                                    0)
            end
        end
      end
    end
  end
end