-
Notifications
You must be signed in to change notification settings - Fork 24
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
RetryHelpers trait to implement non-blocking retries #19
RetryHelpers trait to implement non-blocking retries #19
Conversation
…ults in RetrySettings
…) and RetryHelpers uses exponential backoff
In addition to above, I have now:
|
I have created a new wrapper OpenAIRetryServiceAdapter which uses |
…rom length of results
This reverts commit 945c9dc.
This reverts commit 5af7e34.
Good work! I like that retries are usable both, within the wrapper class, as well as with an implicit "monkey patching". Just three changes:
Regarding new exceptions I will add those once this PR is merged. Thanx |
or:
If not please be aware that rewriting the code to have an increasing counter will take further effort and the code may be more complicated (additional parameters in method calls). Also, could you write tests in RetryHelpersSpec that indicate the exact behavior you require?
"RetrySettings" should {
"allow easy configuration of a constant interval" in {
val interval = 10.seconds
val result = RetrySettings(interval)
result.delayBase shouldBe 0
result.delayOffset shouldBe interval
}
}
"RetryHelpers" should {
"compute the correct delay when using constant interval" in {
val interval = 10.seconds
val settings = RetrySettings(interval)
delay(1)(settings) shouldBe interval
delay(5)(settings) shouldBe interval
}
"compute the correct delay when using strictly positive base" in {
val settings = RetrySettings(
maxRetries = 5,
delayOffset = 2.seconds,
delayBase = 2
)
delay(1)(settings) shouldBe 4.seconds
delay(2)(settings) shouldBe 6.seconds
delay(3)(settings) shouldBe 10.seconds
}
} |
…pecified using RetrySettings(interval)
Hey @phelps-sg , Cheers! |
Note that I just realised readme needs to be updated with new retry behaviour, which I have just done. Will resolve conflicts shortly. |
@peterbanda the checks above are failing because of formatting. You can merge and override checks, or alternatively apply formatting in this branch. I will hold fire unless hear otherwise. Let me know if you need any help resolving issues with the CI. |
See #33 for resolving the pipeline issues. Let me know if you want to merge it into this branch. |
io/cequence/openaiscala/RetryHelpers.scala
to allow API calls to be made with non-blocking retries as a possible solution to (fixes Blocking IO in OpenAIRetryServiceAdapter #15, and partial implementation of OpenAIRetryServiceAdapter retries non-retryable errors #16).RetryHelpers
(Missing unit tests #24).io.cequence.openaiscala.service.OpenAIServiceWrapper
inopenai-client
package which usesRetryHelpers
.Example usage below.
This design has advantages on the client side we can easily apply retry for specific methods, or use different retry settings for different methods (without necessarily having to create separate wrappers).