Skip to content

Commit 54c2301

Browse files
authored
cap auto-refresh max attempt when invoking generateCompletion (#4541)
1 parent 8c109af commit 54c2301

File tree

1 file changed

+16
-4
lines changed
  • plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codewhisperer/service

1 file changed

+16
-4
lines changed

plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codewhisperer/service/CodeWhispererService.kt

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ import java.util.concurrent.TimeUnit
9090

9191
@Service
9292
class CodeWhispererService {
93+
private var refreshFailure: Int = 0
94+
9395
fun showRecommendationsInPopup(
9496
editor: Editor,
9597
triggerTypeInfo: TriggerTypeInfo,
@@ -106,10 +108,18 @@ class CodeWhispererService {
106108
}
107109

108110
if (isQExpired(project)) {
109-
// The purpose to execute in the background is to hide the progress indicator UI
110-
val shouldReauth = ApplicationManager.getApplication().executeOnPooledThread<Boolean> {
111-
promptReAuth(project)
112-
}.get()
111+
// say the connection is un-refreshable if refresh fails for 3 times
112+
val shouldReauth = if (refreshFailure < MAX_REFRESH_ATTEMPT) {
113+
ApplicationManager.getApplication().executeOnPooledThread<Boolean> {
114+
promptReAuth(project)
115+
}.get().also { success ->
116+
if (!success) {
117+
refreshFailure++
118+
}
119+
}
120+
} else {
121+
true
122+
}
113123

114124
if (shouldReauth) {
115125
return
@@ -754,6 +764,8 @@ class CodeWhispererService {
754764

755765
companion object {
756766
private val LOG = getLogger<CodeWhispererService>()
767+
private const val MAX_REFRESH_ATTEMPT = 3
768+
757769
val CODEWHISPERER_CODE_COMPLETION_PERFORMED: Topic<CodeWhispererCodeCompletionServiceListener> = Topic.create(
758770
"CodeWhisperer code completion service invoked",
759771
CodeWhispererCodeCompletionServiceListener::class.java

0 commit comments

Comments
 (0)