Commit 99a036c8 authored by Jonas Waeber's avatar Jonas Waeber
Browse files

Adds logging to service

parent 7ac3dc7c
Pipeline #9132 passed with stages
in 8 minutes and 14 seconds
......@@ -23,7 +23,7 @@ import org.apache.logging.log4j.LogManager
class App {
companion object {
private val log = LogManager.getLogger("SftpReader")
private val log = LogManager.getLogger("App")
@JvmStatic fun main(args: Array<String>) {
try {
val service = Service()
......
......@@ -19,10 +19,12 @@
package org.memobase
import java.io.File
import org.apache.logging.log4j.LogManager
import org.memobase.settings.SettingsLoader
import org.memobase.sftp.SftpClient
class Service(fileName: String = "app.yml") {
val log = LogManager.getLogger("TextFileValidationService")
val settings =
SettingsLoader(
......@@ -39,11 +41,12 @@ class Service(fileName: String = "app.yml") {
fun run() {
producer.use { producer ->
sftpClient.use { sftp ->
log.info("Connected to SFTP & Kafka.")
val validator = FileValidation(sftp)
val files = sftp.listFiles(settings.appSettings.getProperty("directory")).map { File(it) }
val reports = mutableListOf<Report>()
for (file in files) {
log.info("Validate file ${file.absolutePath}.")
val validationResult = validator.validate(file)
producer.sendMessage(validationResult.second.id, validationResult.first)
producer.sendReport(validationResult.second)
......@@ -51,11 +54,13 @@ class Service(fileName: String = "app.yml") {
}
val failures = reports.count { report -> report.status == "FAILURE" }
if (failures > 0) {
log.info("Validation ended with $failures failures!")
producer.sendJobReport(
Report(settings.id, status = "FAILURE", message = "Failed to validate $failures of ${reports.size} files."),
settings.processReportTopic
)
} else {
log.info("Validation was successful!")
producer.sendJobReport(
Report(settings.id, status = "SUCCESS", message = "Successfully validated ${reports.size} files."),
settings.processReportTopic
......
Markdown is supported
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