Skip to content

Commit

Permalink
add base signal handling
Browse files Browse the repository at this point in the history
  • Loading branch information
tombokombo committed Oct 31, 2024
1 parent e02434c commit 1985984
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"net"
"net/http"
"os"
"syscall"
"os/signal"
"sync"
"time"
"strings"
Expand Down Expand Up @@ -114,9 +116,34 @@ func NewProxyServer(configPath string, queueSize, workerCount int) *ProxyServer
go ps.worker(i)
}

signalCh := make(chan os.Signal)
signal.Notify(signalCh, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
go func() {
for sig := range signalCh {
switch sig {
case os.Interrupt:
log.Printf("Got interrput signal")
case syscall.SIGTERM:
log.Printf("Got SIGTERM signal")
// deliver rest of queue to FINAL destination
case syscall.SIGQUIT:
log.Printf("Got SIGQUIT signal")
// deliver rest of queue to FINAL destination
default:
log.Printf("Some signal received: %v\n", sig)
}
log.Printf("Queue len is: %v\n", ps.getQueueLen())
}
}()

return ps
}

// loadConfig loads the configuration from the YAML file
func (p *ProxyServer) getQueueLen() int {
return len(p.queue)
}

// loadConfig loads the configuration from the YAML file
func (p *ProxyServer) loadConfig() error {
data, err := ioutil.ReadFile(p.configPath)
Expand Down

0 comments on commit 1985984

Please sign in to comment.