Skip to content

Commit

Permalink
Move DEFAULT_TIMEOUT into the data store
Browse files Browse the repository at this point in the history
  • Loading branch information
tfausak committed Aug 26, 2014
1 parent 107c786 commit df23afe
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 13 deletions.
9 changes: 0 additions & 9 deletions lib/stoplight.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ module Stoplight
# @return [Integer]
DEFAULT_THRESHOLD = 3

# @return [Integer]
DEFAULT_TIMEOUT = 5 * 60

@data_store = DataStore::Memory.new
@notifiers = [Notifier::StandardError.new]

Expand Down Expand Up @@ -56,11 +53,5 @@ def yellow?(name)
def threshold(name)
data_store.threshold(name) || DEFAULT_THRESHOLD
end

# @param name [String]
# @return [Integer]
def timeout(name)
data_store.timeout(name) || DEFAULT_TIMEOUT
end
end
end
3 changes: 3 additions & 0 deletions lib/stoplight/data_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,8 @@ module DataStore

# @return [String]
COLOR_RED = 'red'.freeze

# @return [Integer]
DEFAULT_TIMEOUT = 5 * 60
end
end
2 changes: 1 addition & 1 deletion lib/stoplight/data_store/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def _color(failures, state, threshold, timeout)
# If the threshold is 0, the light is always red.
return COLOR_RED if failures.empty?

timeout = timeout ? timeout.to_i : Stoplight::DEFAULT_TIMEOUT
timeout = timeout ? timeout.to_i : DEFAULT_TIMEOUT
return COLOR_YELLOW if Time.now - failures.last.time > timeout

COLOR_RED
Expand Down
2 changes: 1 addition & 1 deletion lib/stoplight/data_store/memory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def set_threshold(name, threshold)
# @group Timeout

def timeout(name)
all_timeouts[name]
all_timeouts[name] || DEFAULT_TIMEOUT
end

def set_timeout(name, timeout)
Expand Down
2 changes: 1 addition & 1 deletion lib/stoplight/data_store/redis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def set_threshold(name, threshold)

def timeout(name)
timeout = @redis.hget(timeouts_key, name)
timeout.to_i if timeout
timeout ? timeout.to_i : DEFAULT_TIMEOUT
end

def set_timeout(name, timeout)
Expand Down
2 changes: 1 addition & 1 deletion lib/stoplight/light.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def threshold
end

def timeout
Stoplight.timeout(name)
Stoplight.data_store.timeout(name)
end

def yellow?
Expand Down

0 comments on commit df23afe

Please sign in to comment.