extracted handle signals

This commit is contained in:
pippellia-btc
2025-06-10 16:44:53 +02:00
parent b856f03605
commit b60eb9d10b
3 changed files with 15 additions and 26 deletions

View File

@@ -9,10 +9,8 @@ import (
"github/pippellia-btc/crawler/pkg/redb"
"log"
"os"
"os/signal"
"runtime"
"sync"
"syscall"
"time"
"github.com/nbd-wtf/go-nostr"
@@ -28,7 +26,7 @@ If Redis and the eventstore are already in sync, run the executable at /cmd/craw
func main() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
go handleSignals(cancel)
go pipe.HandleSignals(cancel)
config, err := config.Load()
if err != nil {
@@ -104,16 +102,6 @@ func main() {
wg.Wait()
}
// handleSignals listens for OS signals and triggers context cancellation.
func handleSignals(cancel context.CancelFunc) {
signals := make(chan os.Signal, 1)
signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM)
<-signals
log.Println(" Signal received. Shutting down...")
cancel()
}
// enqueue things into the specified channel or return an error if full.
func enqueue[T any](queue chan T) func(t T) error {
return func(t T) error {