Skip to content

Commit

Permalink
Merge pull request #9 from TPei/fix_removed_time_new
Browse files Browse the repository at this point in the history
Time.new was removed in 0.33.0, needs to be Time.local now
  • Loading branch information
TPei authored Apr 2, 2020
2 parents d77efc6 + 0956316 commit ff3e5e6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions src/circuit_breaker.cr
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class CircuitBreaker
# ```
def initialize(threshold @error_threshold, timewindow timeframe, reenable_after @duration, handled_errors = [] of Exception, ignored_errors = [] of Exception)
@state = CircuitState.new
@reclose_time = Time.new
@reclose_time = Time.local
@error_watcher = ErrorWatcher.new(Time::Span.new(0, 0, timeframe))

# two-step initialization because of known crystal compiler bug
Expand Down Expand Up @@ -105,13 +105,13 @@ class CircuitBreaker
private def trip
@state.trip

@reclose_time = Time.new + Time::Span.new(0, 0, @duration)
@reclose_time = Time.local + Time::Span.new(0, 0, @duration)
end

private def reset
@state.reset

@reclose_time = Time.new
@reclose_time = Time.local
@error_watcher.reset
end

Expand All @@ -120,7 +120,7 @@ class CircuitBreaker
end

private def reclose?
if Time.new > @reclose_time
if Time.local > @reclose_time
@state.attempt_reset
true
else
Expand All @@ -130,7 +130,7 @@ class CircuitBreaker

private def open_circuit
@state.trip
@reclose_time = Time.new + Time::Span.new(0, 0, @duration)
@reclose_time = Time.local + Time::Span.new(0, 0, @duration)
end
end

Expand Down
6 changes: 3 additions & 3 deletions src/error_watcher.cr
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ class ErrorWatcher
end

def add_failure
@failures << Time.new
@failures << Time.local
end

def add_execution
@executions << Time.new
@executions << Time.local
end

def reset
Expand All @@ -37,7 +37,7 @@ class ErrorWatcher
end

private def clean_old(arr : Array(Time))
threshold = Time.new - @timeframe
threshold = Time.local - @timeframe

arr.reject! { |time| time < threshold }
end
Expand Down

0 comments on commit ff3e5e6

Please sign in to comment.