package application

import (
	"log/slog"
	"os"
	"os/signal"
	"syscall"
)

func (a *Application) signalsListener() {
	slog.Info("Starting listening for SIGTERM signal...")

	listener := make(chan os.Signal, 1)

	signal.Notify(listener, syscall.SIGTERM, os.Interrupt)

	<-listener
	slog.Info("Got SIGTERM, stopping Featurer...")

	if err := a.Shutdown(); err != nil {
		slog.Error("Something went wrong when trying to shutdown application", "error", err.Error())
		slog.Error("!!! APPLICATION CANNOT BE STOPPED NORMALLY, KILL IT MANUALLY !!!")
	}
}
