2017-09-21 09:55:08 -04:00
|
|
|
module Gitlab
|
|
|
|
module Git
|
|
|
|
module Storage
|
|
|
|
class NullCircuitBreaker
|
2017-10-12 08:13:59 -04:00
|
|
|
include CircuitBreakerSettings
|
|
|
|
|
2017-09-21 09:55:08 -04:00
|
|
|
# These will have actual values
|
|
|
|
attr_reader :storage,
|
|
|
|
:hostname
|
|
|
|
|
|
|
|
# These will always have nil values
|
2017-10-12 08:13:59 -04:00
|
|
|
attr_reader :storage_path
|
2017-09-21 09:55:08 -04:00
|
|
|
|
2017-11-13 10:52:07 -05:00
|
|
|
delegate :last_failure, :failure_count, :no_failures?,
|
|
|
|
to: :failure_info
|
|
|
|
|
2017-09-21 09:55:08 -04:00
|
|
|
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
|
|
|
|
|
2017-10-19 02:32:55 -04:00
|
|
|
def backing_off?
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2017-09-21 09:55:08 -04:00
|
|
|
def failure_info
|
2017-11-13 10:52:07 -05:00
|
|
|
@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
|
2017-09-21 09:55:08 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|