Commit 3a2aaed8 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Use a Struct to keep track of failure info

parent 0dd4c306
...@@ -2,6 +2,8 @@ module Gitlab ...@@ -2,6 +2,8 @@ module Gitlab
module Git module Git
module Storage module Storage
class CircuitBreaker class CircuitBreaker
FailureInfo = Struct.new(:last_failure, :failure_count)
attr_reader :storage, attr_reader :storage,
:hostname, :hostname,
:storage_path, :storage_path,
...@@ -10,6 +12,8 @@ module Gitlab ...@@ -10,6 +12,8 @@ module Gitlab
:failure_reset_time, :failure_reset_time,
:storage_timeout :storage_timeout
delegate :last_failure, :failure_count, to: :failure_info
def self.reset_all! def self.reset_all!
pattern = "#{Gitlab::Git::Storage::REDIS_KEY_PREFIX}*" pattern = "#{Gitlab::Git::Storage::REDIS_KEY_PREFIX}*"
...@@ -93,7 +97,7 @@ module Gitlab ...@@ -93,7 +97,7 @@ module Gitlab
end end
def track_storage_inaccessible def track_storage_inaccessible
@failure_info = [Time.now, failure_count + 1] @failure_info = FailureInfo.new(Time.now, failure_count + 1)
Gitlab::Git::Storage.redis.with do |redis| Gitlab::Git::Storage.redis.with do |redis|
redis.pipelined do redis.pipelined do
...@@ -107,7 +111,7 @@ module Gitlab ...@@ -107,7 +111,7 @@ module Gitlab
def track_storage_accessible def track_storage_accessible
return if no_failures? return if no_failures?
@failure_info = [nil, 0] @failure_info = FailureInfo.new(nil, 0)
Gitlab::Git::Storage.redis.with do |redis| Gitlab::Git::Storage.redis.with do |redis|
redis.pipelined do redis.pipelined do
...@@ -117,14 +121,6 @@ module Gitlab ...@@ -117,14 +121,6 @@ module Gitlab
end end
end end
def last_failure
failure_info.first
end
def failure_count
failure_info.last
end
def failure_info def failure_info
@failure_info ||= get_failure_info @failure_info ||= get_failure_info
end end
...@@ -136,7 +132,7 @@ module Gitlab ...@@ -136,7 +132,7 @@ module Gitlab
last_failure = Time.at(last_failure.to_i) if last_failure.present? last_failure = Time.at(last_failure.to_i) if last_failure.present?
[last_failure, failure_count.to_i] FailureInfo.new(last_failure, failure_count.to_i)
end end
def cache_key def cache_key
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment