Adding StartupNotifier
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Urban Modig
2025-09-12 13:24:35 +02:00
parent afcbcbaf12
commit 538421e77e

View File

@ -0,0 +1,29 @@
package se.urmo.electricityalert.notifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
@Component
public class StartupNotifier {
private static final Logger log = LoggerFactory.getLogger(StartupNotifier.class);
private final TelegramNotifier telegramNotifier;
public StartupNotifier(TelegramNotifier telegramNotifier) {
this.telegramNotifier = telegramNotifier;
}
@EventListener(ApplicationReadyEvent.class)
public void notifyStartup() {
String msg = "🔄 Electricity Alert Service has restarted and is running.";
try {
telegramNotifier.send(msg);
log.info("Sent startup notification: {}", msg);
} catch (Exception e) {
log.warn("Failed to send startup notification", e);
}
}
}