-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use strongly-typed
Duration
s for time
This PR improves time & duration handling in Riff Raff by switching representation from `Int` or `Long` types (types which do not incorporate a time-unit, meaning we have to work out from _context_ whether we are using seconds, milliseconds, epoch-ms, etc) to using the great `java.time.*` classes `Instant` & `Duration`. This fixes a lot of things like: * slightly obscure integer constants like `5 * 60 * 1000` (denoting 5 minutes) * the inability of the compiler to check we are performing the right kind of operation to change time-units - the compiler can't know if what we're doing to an `Int` makes sense! * variable names like `durationMillis`, where 'millis' had to be included because the declared type of `Long` isn't _telling_ us what the type is * frequent multiplication by 1000 to transform a value that we are quite sure is measured in seconds, into milliseconds! * the risk that integer arithmetic might overflow when making time calculations, silently corrupting the answer. If you can use a strongly-typed time class instead - like `Duration` or `Instant` - the compiler and library author can do all of that stuff for us, it's much better! You also stand a better chance of avoiding the hallowed [_falsehoods programmers believe about time_](https://gist.github.com/timvisee/fcda9bbdff88d45cc9061606b4b923ca). ### From `Param[Int]` to `Param[Duration]` - durations are still specified in seconds ⏱️ Riff Raff has several parameters which specify durations (eg `healthcheckGrace`, `warmupGrace`, etc). Historically these have all expected integer values and been documented to be duration in **seconds**: ```yaml parameters: healthcheckGrace: 420 warmupGrace: 300 ``` We don't want to make everyone change their Riff Raff configuration, and so those parameters need to continue to accept the same numeric values and still interpret them as seconds. The `Param.waitingSecondsFor()` helper method lets us create parameters that are a `Param[Duration]` (which could have been problematic because `java.time.Duration` has no _specified_ time unit) that still _explicitly_ parse their input as seconds, and are tested to do so. ### Migrating from Joda-Time to java.time We should be using `java.time.*` classes in our codebases, in preference to the wonderful but old Joda-Time library: https://blog.joda.org/2014/11/converting-from-joda-time-to-javatime.html See also: * guardian/ophan#3988 - another PR achieving a similar thing for Ophan
- Loading branch information
Showing
15 changed files
with
296 additions
and
277 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
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
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.