MCPcopy Create free account
hub / github.com/OpenFunction/samples / monitor

Function monitor

functions/async/pubsub/producer/producer.go:94–120  ·  view source on GitHub ↗
(resultCh <-chan bool, stopCh <-chan struct{})

Source from the content-addressed store, hash-verified

92}
93
94func monitor(resultCh <-chan bool, stopCh <-chan struct{}) {
95 var mux sync.Mutex
96 var successCounter int64 = 0
97 var errorCounter int64 = 0
98 startTime := time.Now()
99 tickerCh := time.NewTicker(logFrequency).C
100 for {
101 select {
102 case r := <-resultCh:
103 mux.Lock()
104 if r {
105 successCounter++
106 } else {
107 errorCounter++
108 }
109 mux.Unlock()
110 case <-tickerCh:
111 var avg float64 = 0
112 if successCounter > 0 {
113 avg = float64(successCounter) / time.Since(startTime).Seconds()
114 }
115 logger.Printf("%10d published, %3.0f/sec, %3d errors", successCounter, avg, errorCounter)
116 case <-stopCh:
117 os.Exit(0)
118 }
119 }
120}
121
122func publish(index int, resultCh chan<- bool, stopCh <-chan struct{}) {
123 delayCh := time.NewTicker(publishDelay).C

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected