-
Notifications
You must be signed in to change notification settings - Fork 241
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
fix(amazonq): Adding backoff and retry for export result archive streaming API. #5320
base: main
Are you sure you want to change the base?
Conversation
@@ -85,8 +108,43 @@ class AmazonQStreamingClient(private val project: Project) { | |||
return byteBufferList | |||
} | |||
|
|||
/** |
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.
nit: If possible we can move this to a shared place.
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.
Felt it was alright to keep it here in AmazonQStreamingClient class. Assuming that any other streaming APIs will be added here.
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.
isn't this the same idea as 5470418#diff-b08b1d5a6c68d78f0cdb5d0ff07528a20d2d60156313fd4c4f1a41b69e2a4f36R212
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.
this streaming API is a suspend function. tried using a common function for both but way to many conflicts
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.
you can have a thin wrapper for the non-suspending use case instead of duplicating the logic
fun execute( | ||
operation: () -> T, | ||
isRetryable: (Exception) -> Boolean = { it is RetryableException }, | ||
errorHandler: ((Exception, Int) -> Nothing)? = null, | ||
): T { | ||
while (attempts < MAX_RETRY_ATTEMPTS) { | ||
try { | ||
return operation() | ||
} catch (e: Exception) { | ||
attempts++ | ||
if (attempts >= MAX_RETRY_ATTEMPTS || !isRetryable(e)) { | ||
errorHandler?.invoke(e, attempts) ?: throw e | ||
} | ||
|
||
Thread.sleep(getJitteredDelay()) | ||
} | ||
} | ||
|
||
throw RuntimeException("Unexpected state after $attempts attempts") | ||
} |
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.
fun execute( | |
operation: () -> T, | |
isRetryable: (Exception) -> Boolean = { it is RetryableException }, | |
errorHandler: ((Exception, Int) -> Nothing)? = null, | |
): T { | |
while (attempts < MAX_RETRY_ATTEMPTS) { | |
try { | |
return operation() | |
} catch (e: Exception) { | |
attempts++ | |
if (attempts >= MAX_RETRY_ATTEMPTS || !isRetryable(e)) { | |
errorHandler?.invoke(e, attempts) ?: throw e | |
} | |
Thread.sleep(getJitteredDelay()) | |
} | |
} | |
throw RuntimeException("Unexpected state after $attempts attempts") | |
} | |
fun execute( | |
operation: () -> T, | |
isRetryable: (Exception) -> Boolean = { it is RetryableException }, | |
errorHandler: ((Exception, Int) -> Nothing)? = null, | |
): T = runBlocking { | |
executeSuspend(operation, isRetryable, errorHandler) | |
} |
?
@@ -91,3 +115,60 @@ class AmazonQStreamingClient(private val project: Project) { | |||
fun getInstance(project: Project) = project.service<AmazonQStreamingClient>() | |||
} | |||
} | |||
|
|||
class RetryableOperation<T> { |
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.
move to its own file
Types of changes
Description
We have seen rise of the ExportResultArchive API failures to 15 per week, with retryable error messages.
Adding backoff and retry to mitigate these errors.
Checklist
License
I confirm that my contribution is made under the terms of the Apache 2.0 license.