feat: use logrus

Signed-off-by: Sphericalkat <amolele@gmail.com>
This commit is contained in:
sphericalkat committed 2023-05-26 19:42:53 +05:30
1 parent 6117c82d32
commit 244804fe85
6 files changed
+168 -4

No files matched your search

+34
View File
@@ -0,0 +1,34 @@
package lifecycle
import (
"context"
"os"
"os/signal"
"sync"
"syscall"
log "github.com/sirupsen/logrus"
)
// ShutdownListener listens for shutdown OS signals and then gracefully stops tasks using the context
func ShutdownListener(
wg *sync.WaitGroup,
cf *context.CancelFunc,
) {
// create channel to notify on system signals
termChan := make(chan os.Signal, 1)
signal.Notify(termChan, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
// wait for signal
sig := <-termChan
log.Printf("Received signal %v, gracefully shutting down services", sig)
// close channel
close(termChan)
// cancel background context
(*cf)()
// mark shutdown task as done
wg.Done()
}