Skip to content

Commit

Permalink
Minor cleanup and changes to config.
Browse files Browse the repository at this point in the history
  • Loading branch information
Bram-- committed Feb 16, 2024
1 parent afafbf6 commit e7f0c99
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
1 change: 1 addition & 0 deletions examples/java/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ dependencies {
testImplementation(platform("org.junit:junit-bom:5.9.1"))
testImplementation("org.junit.jupiter:junit-jupiter")
}

tasks.named<JavaExec>("run") {
standardInput = System.`in`
}
Expand Down
19 changes: 9 additions & 10 deletions src/main/kotlin/org/audux/bgg/BggClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import org.audux.bgg.request.user
import org.audux.bgg.response.Family
import org.audux.bgg.response.Response
import org.audux.bgg.response.Thing
import org.jetbrains.annotations.VisibleForTesting

/**
* Unofficial Board Game Geek API Client for the
Expand All @@ -79,7 +80,7 @@ object BggClient {
setLoggerSeverity(Severity.Warn)
}

var engine = { CIO.create() }
@VisibleForTesting var engine = { CIO.create() }

/**
* Request details about a user's collection.
Expand Down Expand Up @@ -449,22 +450,20 @@ object BggClient {

internal val client = {
HttpClient(engine()) {
install(ClientRateLimitPlugin) { requestLimit = 10 }
install(ClientRateLimitPlugin) { requestLimit = 25 }
install(HttpRequestRetry) {
exponentialDelay()
retryIf(maxRetries = 5) { request, response ->
retryIf(maxRetries = 10) { request, response ->
response.status.value.let {
// Add 429 (TooManyRequests) and 202 (Accepted) for retries, see:
// https://boardgamegeek.com/thread/1188687/export-collections-has-been-updated-xmlapi-develop
val shouldRetry = it in (500..599) + 202 + 429

if (shouldRetry) {
Logger.i("HttpRequestRetry") {
"Got status code $it Retrying request[${request.url}]."
(it in (500..599) + 202 + 429).also { shouldRetry ->
if (shouldRetry) {
Logger.i("HttpRequestRetry") {
"Got status code $it Retrying request[${request.url}"
}
}
}

shouldRetry
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class ConcurrentRequestLimiter(private val requestLimit: Int) {
break
}

logger.d(tag = "ConcurrentRequestLimiter") {
logger.v(tag = "ConcurrentRequestLimiter") {
"Concurrent Requests limit reached[$currentInFlightRequests/$requestLimit]"
}

Expand Down

0 comments on commit e7f0c99

Please sign in to comment.