Skip to content

Commit

Permalink
feat: add not found, deserialize error cases, refactor gradle kts
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolaiSviridov committed Dec 6, 2023
1 parent 644f299 commit 1106f40
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 13 deletions.
16 changes: 16 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
plugins {
kotlin("jvm") version "1.9.21"
}

repositories {
mavenCentral()
}

subprojects {
group = "org.jetbrains.research.ictl"
version = "0.0.2"

apply {
apply(plugin = "org.jetbrains.kotlin.jvm")
}
}
9 changes: 4 additions & 5 deletions cli/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
val version = "0.0.1"

plugins {
kotlin("jvm") version "1.9.21"
id("application")
id("com.google.cloud.tools.jib") version "3.4.0"
}

val projectVersion = version as String

tasks {
jib {
container {
Expand All @@ -22,8 +21,8 @@ tasks {
}
}
to {
image = "ghcr.io/jetbrains-research/mr-loader/${rootProject.name}:$version"
tags = setOf("latest", version)
image = "ghcr.io/jetbrains-research/mr-loader/${rootProject.name}:$projectVersion"
tags = setOf("latest", projectVersion)
}
}

Expand Down
6 changes: 1 addition & 5 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
plugins {
kotlin("jvm") version "1.9.21"
id("io.ktor.plugin") version "2.2.4"
kotlin("plugin.serialization").version("1.9.21")
kotlin("plugin.serialization") version "1.9.21"
}

group = "org.jetbrains.research.ictl"
version = "0.0.1"

val ktorVersion = "2.2.4"

repositories {
Expand Down
28 changes: 27 additions & 1 deletion core/src/main/kotlin/loader/gerrit/LoaderChanges.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ class LoaderChanges(

// TODO: needs check
private val IGNORE_PROJECTS = setOf("All-Projects", "All-Users")
private const val NOT_FOUND = "Not found:"
private const val DESERIALIZE_ERROR =
"Deserialize error : There seems to be a change in response from the server side. Please report."

fun baseUrlToDomain(baseUrl: String) = baseUrl
.removePrefix("http://")
Expand All @@ -56,6 +59,7 @@ class LoaderChanges(
// TODO: replace
private val logger = run {
val result = Logger.getLogger("loader")
resultDir.mkdirs()
val fh = FileHandler(File(resultDir, "loader.log").absolutePath)
result.addHandler(fh)
val formatter = SimpleFormatter()
Expand Down Expand Up @@ -169,7 +173,19 @@ class LoaderChanges(

val callable = Callable {
runBlocking {
wrapIgnoringErrors { client.getChangeRaw(baseUrl, id) }?.let { rawJson ->
wrapIgnoringErrors {
val rawJson = client.getChangeRaw(baseUrl, id)

if (rawJson.startsWith(NOT_FOUND)) {
throw Exception(rawJson)
}

try {
decodeRawJson<ChangeMetaData>(rawJson)
} catch (e: Exception) {
throw Exception("$DESERIALIZE_ERROR : ChangeId $id")
}

jsonObjectBuffer.addEntry(rawJson, id)
}
logger.info("Loaded changes for $id")
Expand Down Expand Up @@ -232,6 +248,16 @@ class LoaderChanges(
continue
}

errMsg.contains(NOT_FOUND) -> {
logger.warning(errMsg)
return null
}

errMsg.contains(DESERIALIZE_ERROR) -> {
logger.severe("$DESERIALIZE_ERROR : $msg")
return null
}

numOfErrors > maxNumOfErrors -> {
logger.severe("Number of errors for task exceeded threshold=$maxNumOfErrors : $msg : $errMsg")
return null
Expand Down
2 changes: 0 additions & 2 deletions run.sh

This file was deleted.

0 comments on commit 1106f40

Please sign in to comment.