Skip to content

Commit 1985984

Browse files
committed
add base signal handling
1 parent e02434c commit 1985984

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

main.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
"net"
1010
"net/http"
1111
"os"
12+
"syscall"
13+
"os/signal"
1214
"sync"
1315
"time"
1416
"strings"
@@ -114,9 +116,34 @@ func NewProxyServer(configPath string, queueSize, workerCount int) *ProxyServer
114116
go ps.worker(i)
115117
}
116118

119+
signalCh := make(chan os.Signal)
120+
signal.Notify(signalCh, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
121+
go func() {
122+
for sig := range signalCh {
123+
switch sig {
124+
case os.Interrupt:
125+
log.Printf("Got interrput signal")
126+
case syscall.SIGTERM:
127+
log.Printf("Got SIGTERM signal")
128+
// deliver rest of queue to FINAL destination
129+
case syscall.SIGQUIT:
130+
log.Printf("Got SIGQUIT signal")
131+
// deliver rest of queue to FINAL destination
132+
default:
133+
log.Printf("Some signal received: %v\n", sig)
134+
}
135+
log.Printf("Queue len is: %v\n", ps.getQueueLen())
136+
}
137+
}()
138+
117139
return ps
118140
}
119141

142+
// loadConfig loads the configuration from the YAML file
143+
func (p *ProxyServer) getQueueLen() int {
144+
return len(p.queue)
145+
}
146+
120147
// loadConfig loads the configuration from the YAML file
121148
func (p *ProxyServer) loadConfig() error {
122149
data, err := ioutil.ReadFile(p.configPath)

0 commit comments

Comments
 (0)