1
0
Fork 0
mirror of https://github.com/postmannen/ctrl.git synced 2024-12-14 12:37:31 +00:00
ctrl/subscribers.go

63 lines
1.9 KiB
Go
Raw Normal View History

2021-02-24 09:58:02 +00:00
package steward
import (
"fmt"
"github.com/prometheus/client_golang/prometheus"
2021-02-24 09:58:02 +00:00
)
func (s *server) subscribersStart() {
// Start a subscriber for CLICommand messages
2021-02-24 09:58:02 +00:00
{
fmt.Printf("Starting CLICommand subscriber: %#v\n", s.nodeName)
sub := newSubject(CLICommand, CommandACK, s.nodeName)
proc := newProcess(s.processes, sub, s.errorKernel.errorCh, processKindSubscriber, []node{"central", "ship2"}, nil)
2021-02-24 09:58:02 +00:00
// fmt.Printf("*** %#v\n", proc)
2021-03-03 13:14:32 +00:00
go proc.spawnWorker(s)
2021-02-24 09:58:02 +00:00
}
// Start a subscriber for textLogging messages
{
fmt.Printf("Starting textlogging subscriber: %#v\n", s.nodeName)
sub := newSubject(TextLogging, EventACK, s.nodeName)
proc := newProcess(s.processes, sub, s.errorKernel.errorCh, processKindSubscriber, []node{"*"}, nil)
2021-02-24 09:58:02 +00:00
// fmt.Printf("*** %#v\n", proc)
2021-03-03 13:14:32 +00:00
go proc.spawnWorker(s)
2021-02-24 09:58:02 +00:00
}
// Start a subscriber for SayHello messages
{
fmt.Printf("Starting SayHello subscriber: %#v\n", s.nodeName)
sub := newSubject(SayHello, EventNACK, s.nodeName)
proc := newProcess(s.processes, sub, s.errorKernel.errorCh, processKindSubscriber, []node{"*"}, nil)
2021-02-24 09:58:02 +00:00
// fmt.Printf("*** %#v\n", proc)
2021-03-03 13:14:32 +00:00
go proc.spawnWorker(s)
2021-02-24 09:58:02 +00:00
}
if s.centralErrorLogger {
// Start a subscriber for ErrorLog messages
{
fmt.Printf("Starting ErrorLog subscriber: %#v\n", s.nodeName)
sub := newSubject(ErrorLog, EventNACK, "errorCentral")
proc := newProcess(s.processes, sub, s.errorKernel.errorCh, processKindSubscriber, []node{"*"}, nil)
proc.procFunc = func() error {
sayHelloNodes := make(map[node]struct{})
for {
m := <-proc.procFuncCh
sayHelloNodes[m.FromNode] = struct{}{}
// update the prometheus metrics
s.metrics.metricsCh <- metricType{
metric: prometheus.NewGauge(prometheus.GaugeOpts{
Name: "hello_nodes",
Help: "The current number of total nodes who have said hello",
}),
value: float64(len(sayHelloNodes)),
}
}
}
2021-03-03 13:14:32 +00:00
go proc.spawnWorker(s)
}
}
2021-02-24 09:58:02 +00:00
}