-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Scheduled and repeat API + retry refactoring #172
Merged
Merged
Changes from 13 commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
f5a0581
refactor retry* functions to scheduled*
micossow 1c14d0e
refactor Schedule.Every -> FixedRate
micossow c449e30
refactor schedule -> runScheduled and add repeat*
micossow f526f74
fix compilation error
micossow c27ed5d
fix compilation error and warnings
micossow 3728c62
fix doc compile
micossow d511f02
add Schedule.InitialDelay, refactor Exponential.initialDelay -> first…
micossow 373ee38
Schedule doc cleanup and disambiguation
micossow c68a9d6
add todo
micossow 686e152
remove Schedule.FixedRate and move the start-to-start concept to runS…
micossow bfa4da0
fix default delayPolicy for retry
micossow a3e71b3
add tolerance to fixedRate tests
micossow cc73acc
reduce sleep time in fixedRate tests
micossow d0d94b0
refactor runScheduled -> scheduled
micossow 6406eff
refactor RetryPolicy -> RetryConfig
micossow 013bbdf
refactor Schedule.fallbackTo -> andThen
micossow e1a5805
close todo
micossow 3ba7005
fix compileDocumentation
micossow 90d2164
restore private modifier to Exponential.delay
micossow 8c3128e
[doc] replace policy with config where applicable
micossow 3569463
[doc] repeat and RepeatConfig doc
micossow 8834a18
add initialDelay to RepeatConfig
micossow 60e51b6
another Schedule refactoring
micossow 5c6ef40
refactor DelayPolicy -> SleepMode
micossow 88e9cec
fix initialDelay combined with forever schedule
micossow 739f1a7
add ImmediateRepeatTest
micossow 3715c25
add adr
micossow 732c37e
update docs
micossow e9d7660
fix accidentally modified generated doc
micossow e716e77
reformat adr
micossow 809275d
fix doc
micossow 8f9cbc7
refactor attempt -> iteration in Schedule
micossow c966a90
remove shouldContinueOnError from repeat
micossow a893508
[doc] update repeat doc about combination with retry
micossow 657534a
refactor variable/parameter names in scheduled
micossow 0483281
document to prefer to use repeat, retry instead of scheduled
micossow 6bfb177
[doc] mention how Retry/RetryConfig are special case of ScheduledConfig
micossow 493888f
scheduled: rename iteration -> invocation
micossow a25f23e
fix doc compile
micossow 5b3290c
combining Schedules refactoring and examples
micossow File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 was deleted.
Oops, something went wrong.
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
2 changes: 1 addition & 1 deletion
2
...src/main/scala/ox/resilience/Jitter.scala → ...src/main/scala/ox/scheduling/Jitter.scala
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,30 @@ | ||
package ox.scheduling | ||
|
||
import scala.concurrent.duration.FiniteDuration | ||
import scala.concurrent.duration.DurationInt | ||
|
||
case class RepeatConfig[E, T]( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
schedule: Schedule, | ||
shouldContinueOnError: E => Boolean = (_: E) => false, | ||
shouldContinueOnResult: T => Boolean = (_: T) => true | ||
) | ||
|
||
object RepeatConfig: | ||
def immediate[E, T](repeats: Int): RepeatConfig[E, T] = RepeatConfig(Schedule.Immediate(repeats)) | ||
def immediateForever[E, T]: RepeatConfig[E, T] = RepeatConfig(Schedule.Immediate.forever) | ||
|
||
def fixedRate[E, T](repeats: Int, delay: FiniteDuration): RepeatConfig[E, T] = RepeatConfig(Schedule.Delay(repeats, delay)) | ||
def fixedRateForever[E, T](delay: FiniteDuration): RepeatConfig[E, T] = RepeatConfig(Schedule.Delay.forever(delay)) | ||
|
||
def exponential[E, T]( | ||
repeats: Int, | ||
firstDelay: FiniteDuration, | ||
maxDelay: FiniteDuration = 1.minute, | ||
jitter: Jitter = Jitter.None | ||
): RepeatConfig[E, T] = RepeatConfig(Schedule.Exponential(repeats, firstDelay, maxDelay, jitter)) | ||
|
||
def exponentialForever[E, T]( | ||
firstDelay: FiniteDuration, | ||
maxDelay: FiniteDuration = 1.minute, | ||
jitter: Jitter = Jitter.None | ||
): RepeatConfig[E, T] = RepeatConfig(Schedule.Exponential.forever(firstDelay, maxDelay, jitter)) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't the delay policy be part of
RetryPolicy
, so that it's also user-configurable if needed?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My idea was to create a public API
runScheduled*
with the all configurable options and makeretry*
andrepeat*
as "thin" as possible - basically an opinionated variants ofrunScheduled*
, specifically:retry
- that behaves similarly to resillience4j retries, where sleep time is counted since the end of previous operation, has an optionalonRetry
callback and initial delay (sleep before first operation) is not relevantrepeat
- that behaves similarly to Akka'sSource.tick
, where sleep time is counted since the start of previous operation (interval), doesn't exposeonRepeat
callback (not relevant) and initial delay is allowedWDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, sounds good. Let's just document these defaults quite clearly, plus all the flexibility that
runScheduled
(or maybe simplyscheduled
?) gives you