87 lines
3.2 KiB
Java
87 lines
3.2 KiB
Java
import de.vertico.starface.module.core.model.VariableType;
|
|
import de.vertico.starface.module.core.model.Visibility;
|
|
import de.vertico.starface.module.core.runtime.IBaseExecutable;
|
|
import de.vertico.starface.module.core.runtime.IRuntimeEnvironment;
|
|
import de.vertico.starface.module.core.runtime.annotations.Function;
|
|
import de.vertico.starface.module.core.runtime.annotations.OutputVar;
|
|
|
|
import java.nio.file.*;
|
|
|
|
/**
|
|
* Mail2FaxCleanup - Cleanup Block für Mail2Fax
|
|
*
|
|
* Dieser Block sollte beim "activate" Event des Moduls ausgeführt werden.
|
|
* Er stellt sicher, dass nach einem Server-Absturz oder Modul-Reload
|
|
* keine verwaisten Locks existieren.
|
|
*
|
|
* Hinweis: Der ReentrantLock ist ein In-Memory Lock und wird automatisch
|
|
* beim Server-Neustart freigegeben. Dieser Block ist hauptsächlich für
|
|
* Modul-Reloads ohne Server-Neustart gedacht.
|
|
*
|
|
* Für STARFACE 8.x, 9.x, 10.x (Java 21)
|
|
*/
|
|
@Function(
|
|
visibility = Visibility.Private,
|
|
description = "Cleanup für Mail2Fax - beim Modul-Start ausführen"
|
|
)
|
|
public class Mail2FaxCleanup implements IBaseExecutable {
|
|
|
|
private static final String DATA_DIR = "/var/starface/module-data";
|
|
|
|
@OutputVar(
|
|
label = "Status",
|
|
description = "Cleanup-Status-Meldung",
|
|
type = VariableType.STRING
|
|
)
|
|
public String statusMessage = "";
|
|
|
|
@Override
|
|
public void execute(IRuntimeEnvironment runtime) throws Exception {
|
|
org.apache.logging.log4j.Logger log = runtime.getLog();
|
|
|
|
try {
|
|
log.info("Mail2Fax Cleanup: Starte Cleanup");
|
|
|
|
// Datenverzeichnis prüfen
|
|
Path dataDir = Paths.get(DATA_DIR);
|
|
if (!Files.exists(dataDir)) {
|
|
log.info("Mail2Fax Cleanup: Datenverzeichnis existiert nicht, nichts zu tun");
|
|
statusMessage = "OK - Keine Daten vorhanden";
|
|
return;
|
|
}
|
|
|
|
// Prüfe auf Tracking-Dateien
|
|
Path processedFile = Paths.get(DATA_DIR + "/mail2fax_processed.txt");
|
|
Path retryFile = Paths.get(DATA_DIR + "/mail2fax_retry.txt");
|
|
|
|
int processedCount = 0;
|
|
int retryCount = 0;
|
|
|
|
if (Files.exists(processedFile)) {
|
|
processedCount = Files.readAllLines(processedFile).size();
|
|
}
|
|
|
|
if (Files.exists(retryFile)) {
|
|
retryCount = (int) Files.lines(retryFile)
|
|
.filter(line -> !line.trim().isEmpty())
|
|
.count();
|
|
}
|
|
|
|
log.info("Mail2Fax Cleanup: " + processedCount + " verarbeitete Nachrichten, " +
|
|
retryCount + " wartende Retries");
|
|
|
|
// Der ReentrantLock ist ein In-Memory Lock und existiert nur während
|
|
// der Laufzeit. Bei einem Server-Neustart oder Modul-Reload wird eine
|
|
// neue Instanz erstellt. Es gibt keine Lock-Datei die gelöscht werden muss.
|
|
|
|
statusMessage = "OK - " + processedCount + " verarbeitete, " + retryCount + " Retries";
|
|
log.info("Mail2Fax Cleanup: Abgeschlossen");
|
|
|
|
} catch (Exception e) {
|
|
String msg = "Cleanup-Fehler: " + e.getMessage();
|
|
log.error("Mail2Fax Cleanup: " + msg, e);
|
|
statusMessage = msg;
|
|
}
|
|
}
|
|
}
|