Adding StartupNotifier
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user