Skip to content

Commit f5518a7

Browse files
authored
fix(server): don't cache artifact generation failure (#1940)
Resolves #1938. Before this change, if there was a failure during binding generation which result in an exception, it was actually cached and returned to the user for the next hour. This change causes the server to not cache the failure, and instead let the user retry.
1 parent a80f236 commit f5518a7

File tree

5 files changed

+14
-28
lines changed

5 files changed

+14
-28
lines changed

jit-binding-server/src/main/kotlin/io/github/typesafegithub/workflows/jitbindingserver/ArtifactRoutes.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import kotlinx.coroutines.launch
2727

2828
private val logger = logger { }
2929

30-
typealias CachedVersionArtifact = Result<Map<String, Artifact>?>
30+
typealias CachedVersionArtifact = Map<String, Artifact>?
3131

3232
private val prefetchScope = CoroutineScope(Dispatchers.IO)
3333

@@ -119,7 +119,7 @@ private suspend fun ApplicationCall.toBindingArtifacts(
119119
if (refresh) {
120120
bindingsCache.invalidate(actionCoords)
121121
}
122-
return bindingsCache.get(actionCoords).getOrThrow()
122+
return bindingsCache.get(actionCoords)
123123
}
124124

125125
private fun PrometheusMeterRegistry.incrementArtifactCounter(call: ApplicationCall) {

jit-binding-server/src/main/kotlin/io/github/typesafegithub/workflows/jitbindingserver/Main.kt

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ private fun buildBindingsCache(
8282
.newBuilder()
8383
.refreshAfterWrite(1.hours)
8484
.recordStats()
85-
.asLoadingCache<ActionCoords, CachedVersionArtifact> { runCatching { buildVersionArtifacts(it) } }
85+
.asLoadingCache<ActionCoords, CachedVersionArtifact> { buildVersionArtifacts(it) }
8686

8787
@Suppress("ktlint:standard:function-signature") // Conflict with detekt.
8888
private fun buildMetadataCache(
@@ -95,13 +95,11 @@ private fun buildMetadataCache(
9595
.refreshAfterWrite(1.hours)
9696
.recordStats()
9797
.asLoadingCache<ActionCoords, CachedMetadataArtifact> {
98-
runCatching {
99-
buildPackageArtifacts(
100-
it,
101-
getGithubAuthToken(),
102-
{ coords -> prefetchBindingArtifacts(coords, bindingsCache) },
103-
)
104-
}
98+
buildPackageArtifacts(
99+
it,
100+
getGithubAuthToken(),
101+
{ coords -> prefetchBindingArtifacts(coords, bindingsCache) },
102+
)
105103
}
106104

107105
val deliverOnRefreshRoute = System.getenv("GWKT_DELIVER_ON_REFRESH").toBoolean()

jit-binding-server/src/main/kotlin/io/github/typesafegithub/workflows/jitbindingserver/MetadataRoutes.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import io.micrometer.prometheusmetrics.PrometheusMeterRegistry
1414

1515
private val logger = logger { }
1616

17-
typealias CachedMetadataArtifact = Result<Map<String, String>>
17+
typealias CachedMetadataArtifact = Map<String, String>
1818

1919
fun Routing.metadataRoutes(
2020
metadataCache: LoadingCache<ActionCoords, CachedMetadataArtifact>,
@@ -45,7 +45,7 @@ private fun Route.metadata(
4545
if (refresh) {
4646
metadataCache.invalidate(actionCoords)
4747
}
48-
val metadataArtifacts = metadataCache.get(actionCoords).getOrThrow()
48+
val metadataArtifacts = metadataCache.get(actionCoords)
4949

5050
if (refresh && !deliverOnRefreshRoute) return@get call.respondText(text = "OK")
5151

jit-binding-server/src/test/kotlin/io/github/typesafegithub/workflows/jitbindingserver/ArtifactRoutesTest.kt

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,9 @@ class ArtifactRoutesTest :
102102
// When
103103
val response2 = client.get("some-owner/some-action/v4/some-action-v4.pom")
104104
// Then
105-
// This assertion represents an undesired behavior - it should retry generating the binding
106-
// and return the actual POM.
107-
// TODO fix in https://github.com/typesafegithub/github-workflows-kt/issues/1938
108-
response2.status shouldBe HttpStatusCode.InternalServerError
105+
response2.status shouldBe HttpStatusCode.OK
109106

110-
// This assertion represents an undesired behavior - it should call the binding generation twice,
111-
// first with exception, and then when it's successful.
112-
// TODO fix in https://github.com/typesafegithub/github-workflows-kt/issues/1938
113-
verify(exactly = 1) { mockBuildVersionArtifacts(any()) }
107+
verify(exactly = 2) { mockBuildVersionArtifacts(any()) }
114108
}
115109
}
116110
}

jit-binding-server/src/test/kotlin/io/github/typesafegithub/workflows/jitbindingserver/MetadataRoutesTest.kt

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,9 @@ class MetadataRoutesTest :
112112
// When
113113
val response2 = client.get("some-owner/some-action/maven-metadata.xml")
114114
// Then
115-
// This assertion represents an undesired behavior - it should retry generating the artifact
116-
// and return the actual POM.
117-
// TODO fix in https://github.com/typesafegithub/github-workflows-kt/issues/1938
118-
response2.status shouldBe HttpStatusCode.InternalServerError
115+
response2.status shouldBe HttpStatusCode.OK
119116

120-
// This assertion represents an undesired behavior - it should call the artifact generation twice,
121-
// first with exception, and then when it's successful.
122-
// TODO fix in https://github.com/typesafegithub/github-workflows-kt/issues/1938
123-
verify(exactly = 1) { mockBuildPackageArtifacts(any(), any(), any()) }
117+
verify(exactly = 2) { mockBuildPackageArtifacts(any(), any(), any()) }
124118
}
125119
}
126120
}

0 commit comments

Comments
 (0)