|
|
@ -6,23 +6,25 @@ import ( |
|
|
|
) |
|
|
|
|
|
|
|
type worker struct { |
|
|
|
wake chan bool |
|
|
|
group *config.Group |
|
|
|
wakec chan bool |
|
|
|
shutdownc chan bool |
|
|
|
group *config.Group |
|
|
|
debuglvl int |
|
|
|
} |
|
|
|
|
|
|
|
func (w *worker) start(debuglvl int) { |
|
|
|
func (w *worker) start() { |
|
|
|
for { |
|
|
|
if debuglvl > 2 { |
|
|
|
if w.debuglvl > 2 { |
|
|
|
fmt.Printf("%s worker waiting.. \n", w.group.Name) |
|
|
|
} |
|
|
|
<-w.wake |
|
|
|
if debuglvl > 2 { |
|
|
|
<-w.wakec |
|
|
|
if w.debuglvl > 2 { |
|
|
|
fmt.Printf("%s worker wake.. \n", w.group.Name) |
|
|
|
} |
|
|
|
|
|
|
|
for _, h := range w.group.Hosts { |
|
|
|
for _, c := range h.Checks { |
|
|
|
err := c.Check(debuglvl) |
|
|
|
err := c.Check(w.debuglvl) |
|
|
|
if err != nil { |
|
|
|
fmt.Printf("check error: %s\n", err) |
|
|
|
} |
|
|
@ -30,3 +32,34 @@ func (w *worker) start(debuglvl int) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// Wake this worker with a non-blocking push
|
|
|
|
// into the channel
|
|
|
|
func (w *worker) wake() { |
|
|
|
select { |
|
|
|
case w.wakec <- true: |
|
|
|
default: |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// Shutdown this worker with a non-blocking push
|
|
|
|
// into the channel
|
|
|
|
func (w *worker) shutdown() { |
|
|
|
select { |
|
|
|
case w.shutdownc <- true: |
|
|
|
default: |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func makeworker(g *config.Group, d int) *worker { |
|
|
|
return &worker{ |
|
|
|
group: g, |
|
|
|
debuglvl: d, |
|
|
|
// This channel is unbuffered so that checks that take
|
|
|
|
// over the set interval don't backlog
|
|
|
|
wakec: make(chan bool), |
|
|
|
// This channel is buffered because we want it to remember
|
|
|
|
// an order to shutdown
|
|
|
|
shutdownc: make(chan bool, 1), |
|
|
|
} |
|
|
|
} |