Commit 3ea4c13e authored by Jonas Waeber's avatar Jonas Waeber
Browse files

Remove processed reports!

parent ecd51662
Pipeline #27923 passed with stages
in 4 minutes and 10 seconds
......@@ -55,25 +55,32 @@ class ReportCollector(private val importApiUrl: String) {
}
fun check() {
collection
val removedKeys = collection
.filter { it.value.fatal || hasRequired(it.value.stepsCompleted, it.value.type) }
.map { it.value.toRequestBody().toJson(klaxon) }
.forEach {
.map {
log.info("Sending report for report ${it.value.identifier}.")
Pair(it.key, it.value.toRequestBody().toJson(klaxon))
}
.map {
val con = url.openConnection()
val http = con as HttpURLConnection
http.requestMethod = "POST"
http.doOutput = true
http.setFixedLengthStreamingMode(it.size)
http.setFixedLengthStreamingMode(it.second.size)
http.setRequestProperty("Content-Type", "application/json; charset=UTF-8")
http.connect()
http.outputStream.use { os -> os.write(it) }
http.outputStream.use { os -> os.write(it.second) }
if (http.responseCode >= 400) {
http.errorStream.use { errorStream ->
log.error(errorStream.bufferedReader().lines().reduce { s: String?, s2: String? -> s + s2 })
}
}
http.disconnect()
it.first
}
for (key in removedKeys)
collection.remove(key)
}
private fun hasRequired(completed: Int, type: Type): Boolean {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment