Browse Source

command responses

boyska 5 years ago
parent
commit
7c17c971a0
3 changed files with 16 additions and 2 deletions
  1. 1 0
      cmd/circologd/http.go
  2. 8 2
      cmd/circologd/main.go
  3. 7 0
      hub.go

+ 1 - 0
cmd/circologd/http.go

@@ -13,6 +13,7 @@ import (
 	"gopkg.in/mcuadros/go-syslog.v2/format"
 )
 
+// TODO: return a server
 func setupHTTP(hub circolog.Hub) {
 	http.HandleFunc("/", getHTTPHandler(hub))
 	http.HandleFunc("/ws", getWSHandler(hub))

+ 8 - 2
cmd/circologd/main.go

@@ -89,12 +89,18 @@ func main() {
 		select {
 		case sig := <-interrupt:
 			if sig == syscall.SIGHUP {
-				log.Println("Clearing queue")
 				hub.Commands <- circolog.HubFullCommand{Command: circolog.CommandClear}
+				<-hub.Responses
+				log.Println("Queue cleared")
 			}
 			if sig == syscall.SIGUSR1 {
-				log.Println("Pause/resume")
 				hub.Commands <- circolog.HubFullCommand{Command: circolog.CommandPauseToggle}
+				resp := <-hub.Responses
+				if resp.Value.(bool) {
+					log.Println("resumed")
+				} else {
+					log.Println("paused")
+				}
 			}
 			if sig == syscall.SIGTERM || sig == syscall.SIGINT {
 				log.Println("Quitting because of signal", sig)

+ 7 - 0
hub.go

@@ -37,12 +37,16 @@ const (
 type HubFullCommand struct {
 	Command HubCommand
 }
+type CommandResponse struct {
+	Value interface{}
+}
 
 type Hub struct {
 	Register    chan Client
 	Unregister  chan Client
 	LogMessages chan format.LogParts
 	Commands    chan HubFullCommand
+	Responses   chan CommandResponse
 
 	clients map[Client]bool
 	circbuf *ring.Ring
@@ -55,6 +59,7 @@ func NewHub(ringBufSize int) Hub {
 		Unregister:  make(chan Client),
 		LogMessages: make(chan format.LogParts),
 		Commands:    make(chan HubFullCommand),
+		Responses:   make(chan CommandResponse),
 		circbuf:     ring.New(ringBufSize),
 	}
 }
@@ -120,9 +125,11 @@ func (h *Hub) Run() {
 		case cmd := <-h.Commands:
 			if cmd.Command == CommandClear {
 				h.clear()
+				h.Responses <- CommandResponse{Value: true}
 			}
 			if cmd.Command == CommandPauseToggle {
 				active = !active
+				h.Responses <- CommandResponse{Value: active}
 			}
 		}
 	}