forked from cbeer/is_it_working
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from customink/drinks/timing
Add `h.timer` to fail or warn statuses based on execution time
- Loading branch information
Showing
11 changed files
with
186 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Changelog | ||
|
||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), | ||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | ||
|
||
## [1.2.0] - 2019-11-15 | ||
|
||
### Added | ||
|
||
- Checks can be set to a `warn` status when non-critical errors occur. | ||
- Handler now exposes a `timer` method which can wrap a check and ok/warn/fail it based on how long it takes | ||
|
||
### Changed | ||
|
||
- The handler will report an `HTTP 302` status when a run is successful but there are warnings. | ||
|
||
## [1.1.0] - 2019-09-13 | ||
|
||
### Changed | ||
|
||
- Forked from [tribune/is_it_working](https://github.com/tribune/is_it_working). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
module IsItWorking | ||
class Timer | ||
attr_reader :failure_threshold, :filter, :warning_threshold | ||
|
||
def initialize(warn_after: Float::INFINITY, fail_after: Float::INFINITY) | ||
@failure_threshold = fail_after | ||
@warning_threshold = warn_after | ||
@filter = yield | ||
end | ||
|
||
def call | ||
status = filter.status | ||
if fail_timeout_exceeded?(status.time) | ||
status.fail("runtime exceeded critical threshold: #{failure_threshold}ms") | ||
elsif warn_timeout_exceeded?(status.time) | ||
status.warn("runtime exceeded warning threshold: #{warning_threshold}ms") | ||
end | ||
end | ||
|
||
class << self | ||
def run_timers(timers) | ||
timers.each(&:call) | ||
end | ||
end | ||
|
||
private | ||
|
||
def warn_timeout_exceeded?(time) | ||
timeout_exceeded? time, warning_threshold | ||
end | ||
|
||
def fail_timeout_exceeded?(time) | ||
timeout_exceeded? time, failure_threshold | ||
end | ||
|
||
def timeout_exceeded?(time, val) | ||
time * 1000 > val | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module IsItWorking | ||
VERSION = '1.1.0'.freeze | ||
VERSION = '1.2.0'.freeze | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.