Skip to content

Commit

Permalink
Forsøk å catch exception fra flow og logg dem i stedet
Browse files Browse the repository at this point in the history
Vi prøver å finne ut av hvorfor exceptions kastet av ApolloClient
henger coroutine evig. Derfor prøver jeg å ta tak i flow selv og
heller bare logge exceptions. Svaret fra flow blr da bli
at data og er null og vi får en no-op i emitting på channel
for nye responser. Håpet er at evt. hikke fra graf-apiet til
github dermed vil gå over av seg selv.
  • Loading branch information
eivinhb committed Aug 16, 2024
1 parent 90a551c commit b7c7ed1
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/main/kotlin/no/digipost/github/monitoring/GithubGraphql.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
package no.digipost.github.monitoring

import com.apollographql.apollo3.ApolloCall
import com.apollographql.apollo3.ApolloClient
import com.apollographql.apollo3.api.ApolloResponse
import com.apollographql.apollo3.api.Optional
import com.github.graphql.client.GetVulnerabilityAlertsForRepoQuery
import com.github.graphql.client.QueryRepositoriesQuery
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.filterNotNull
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import okhttp3.internal.immutableListOf
Expand Down Expand Up @@ -101,7 +108,9 @@ private suspend fun getVulnerabilitiesForRepo(

while (hasNext) {

val response = apolloClient.query(GetVulnerabilityAlertsForRepoQuery(name, GITHUB_OWNER, after = Optional.present(cursor))).execute()
val response = apolloClient.query(GetVulnerabilityAlertsForRepoQuery(name, GITHUB_OWNER, after = Optional.present(cursor))).toFlow()
.catch { ex -> logger.error("Noe gikk galt i henting av sårbarheter fra Github", ex) }
.first()

val vulnerabilityAlerts = response.data?.repository?.vulnerabilityAlerts?.nodes ?: emptyList()
val vulnerabilities = vulnerabilityAlerts.mapNotNull {
Expand Down Expand Up @@ -137,7 +146,9 @@ private suspend fun listRepos(apolloClient: ApolloClient, repositoryChannel: Cha
while (hasNext) {
if (logger.isDebugEnabled) logger.debug("henter repoer fra Github ${if (cursor != null) " etter: $cursor" else " fra toppen"}")

val response = apolloClient.query(QueryRepositoriesQuery(Optional.Present(cursor))).execute()
val response = apolloClient.query(QueryRepositoriesQuery(Optional.Present(cursor))).toFlow()
.catch { ex -> logger.error("Noe gikk galt i henting av repoer fra Github", ex) }
.first()

response.data?.viewer?.repositories?.nodes
?.filter { GITHUB_OWNER == it?.owner?.login }
Expand All @@ -158,5 +169,6 @@ private suspend fun listRepos(apolloClient: ApolloClient, repositoryChannel: Cha

cursor = response.data?.viewer?.repositories?.pageInfo?.endCursor
}

}

0 comments on commit b7c7ed1

Please sign in to comment.