runId in fileId für Logging umbenannt, neue pipelineRunId eingeführt und ORDS aufruf einmalig ans Ende der Pipeline gesetzt, anstatt nach jeder Datei
This commit is contained in:
@@ -79,38 +79,49 @@ public class FileProcessingPipeline {
|
||||
}
|
||||
|
||||
private void processAll() {
|
||||
Log.info("Pipeline-Lauf gestartet");
|
||||
UUID pipelineRunId = UUID.randomUUID();
|
||||
MDC.put("pipelineRunId", pipelineRunId.toString());
|
||||
Log.infof("Pipeline-Lauf gestartet [pipelineRunId=%s]", pipelineRunId);
|
||||
|
||||
preProcessingCleanup();
|
||||
|
||||
List<String> zipFiles;
|
||||
try {
|
||||
zipFiles = sftpService.listZipFiles();
|
||||
} catch (SftpException e) {
|
||||
Log.errorf(e, "SFTP-Listing fehlgeschlagen — Pipeline-Lauf abgebrochen");
|
||||
return;
|
||||
preProcessingCleanup();
|
||||
|
||||
List<String> zipFiles;
|
||||
try {
|
||||
zipFiles = sftpService.listZipFiles();
|
||||
} catch (SftpException e) {
|
||||
Log.errorf(e, "SFTP-Listing fehlgeschlagen — Pipeline-Lauf abgebrochen");
|
||||
return;
|
||||
}
|
||||
|
||||
if (zipFiles.isEmpty()) {
|
||||
Log.info("Keine neuen ZIP-Dateien auf dem SFTP-Server gefunden");
|
||||
return;
|
||||
}
|
||||
|
||||
Log.infof("%d neue ZIP-Datei(en) auf dem SFTP-Server gefunden", zipFiles.size());
|
||||
|
||||
for (String zipFilename : zipFiles) {
|
||||
Log.infof("ZIP-Datei gefunden: %s", zipFilename);
|
||||
processZip(zipFilename);
|
||||
}
|
||||
|
||||
MDC.put("step", "ords-notify");
|
||||
try {
|
||||
ordsNotificationService.triggerDbProcessing();
|
||||
} catch (OrdsException e) {
|
||||
Log.errorf(e, "ORDS-Benachrichtigung fehlgeschlagen — DB-Verarbeitung wird beim nächsten Lauf ausgelöst");
|
||||
}
|
||||
} finally {
|
||||
Log.infof("Pipeline-Lauf abgeschlossen [pipelineRunId=%s]", pipelineRunId);
|
||||
MDC.clear();
|
||||
}
|
||||
|
||||
if (zipFiles.isEmpty()) {
|
||||
Log.info("Keine neuen ZIP-Dateien auf dem SFTP-Server gefunden");
|
||||
Log.info("Pipeline-Lauf abgeschlossen");
|
||||
return;
|
||||
}
|
||||
|
||||
Log.infof("%d neue ZIP-Datei(en) auf dem SFTP-Server gefunden", zipFiles.size());
|
||||
|
||||
for (String zipFilename : zipFiles) {
|
||||
Log.infof("Datei gefunden: %s", zipFilename);
|
||||
processZip(zipFilename);
|
||||
}
|
||||
|
||||
Log.info("Pipeline-Lauf abgeschlossen");
|
||||
}
|
||||
|
||||
private void processZip(String zipFilename) {
|
||||
ProcessingContext context = new ProcessingContext(UUID.randomUUID(), zipFilename);
|
||||
MDC.put("runId", context.runId.toString());
|
||||
Log.infof("Starte Verarbeitung von '%s' [runId=%s]", zipFilename, context.runId);
|
||||
MDC.put("fileId", context.fileId.toString());
|
||||
Log.infof("Starte Verarbeitung von '%s' [fileId=%s]", zipFilename, context.fileId);
|
||||
|
||||
try {
|
||||
// --- Download ---
|
||||
@@ -142,19 +153,13 @@ public class FileProcessingPipeline {
|
||||
MDC.put("step", "oci-marker");
|
||||
ociUploadService.uploadMarker(context);
|
||||
context.status = ProcessingStatus.MARKER_UPLOADED;
|
||||
|
||||
// --- ORDS Notify ---
|
||||
MDC.put("step", "ords-notify");
|
||||
ordsNotificationService.triggerDbProcessing(context);
|
||||
|
||||
context.status = ProcessingStatus.ORDS_NOTIFIED;
|
||||
Log.infof("Verarbeitung erfolgreich abgeschlossen: '%s'", zipFilename);
|
||||
|
||||
} catch (ZipException e) {
|
||||
Log.errorf(e, "Ungültige ZIP-Datei '%s' — wird zu .error umbenannt", zipFilename);
|
||||
context.status = ProcessingStatus.FAILED;
|
||||
tryRenameToError(zipFilename);
|
||||
} catch (SftpException | OciException | OrdsException e) {
|
||||
} catch (SftpException | OciException e) {
|
||||
Log.errorf(e, "Verarbeitung von '%s' fehlgeschlagen (Infrastruktur): %s", zipFilename, e.getMessage());
|
||||
context.status = ProcessingStatus.FAILED;
|
||||
} catch (IOException e) {
|
||||
@@ -166,10 +171,11 @@ public class FileProcessingPipeline {
|
||||
} finally {
|
||||
postProcessingCleanup(context);
|
||||
long duration = Duration.between(context.startTime, LocalDateTime.now()).toMillis();
|
||||
Log.infof("Lauf %s für Datei %s abgeschlossen — Status: %s, Dauer: %dms",
|
||||
context.runId, zipFilename, context.status, duration);
|
||||
Log.infof("Datei %s abgeschlossen — Status: %s, Dauer: %dms [fileId=%s]",
|
||||
zipFilename, context.status, duration, context.fileId);
|
||||
Log.info("-----------------------------------------------------------------------------------------------------");
|
||||
MDC.clear();
|
||||
MDC.remove("fileId");
|
||||
MDC.remove("step");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -234,7 +240,7 @@ public class FileProcessingPipeline {
|
||||
*/
|
||||
private void postProcessingCleanup(ProcessingContext context) {
|
||||
MDC.put("step", "post-cleanup");
|
||||
Log.infof("Cleanup gestartet für Lauf %s", context.runId);
|
||||
Log.infof("Cleanup gestartet für Datei '%s'", context.zipFilename);
|
||||
try {
|
||||
if (context.localZipPath != null) {
|
||||
Files.deleteIfExists(context.localZipPath);
|
||||
@@ -245,8 +251,8 @@ public class FileProcessingPipeline {
|
||||
Log.infof("Lokales Entpack-Verzeichnis gelöscht: %s", context.localExtractDir);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Log.warnf(e, "Cleanup für Lauf %s fehlgeschlagen — lokale Dateien verbleiben ggf. in %s",
|
||||
context.runId,
|
||||
Log.warnf(e, "Cleanup für '%s' fehlgeschlagen — lokale Dateien verbleiben ggf. in %s",
|
||||
context.zipFilename,
|
||||
context.localZipPath != null ? context.localZipPath.getParent() : "unbekannt");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user