func discovering(wg *sync.WaitGroup) { defer wg.Done() c := make(chan tutum.Event) e := make(chan error) nodes.DiscoverPeers() go tutum.TutumEvents(c, e) Loop: for { select { case event := <-c: if event.Type == "node" && (event.State == "Deployed" || event.State == "Terminated") { err := nodes.DiscoverPeers() if err != nil { log.Println(err) } } break case err := <-e: log.Println("[NODE DISCOVERY ERROR]: " + err.Error()) time.Sleep(5 * time.Second) wg.Add(1) go discovering(wg) break Loop } } }
func nodeEventHandler(eventType string, state string) error { if eventType == "node" && (state == "Deployed" || state == "Terminated") { err := nodes.DiscoverPeers() if err != nil { return err } } return nil }
func discovering(wg *sync.WaitGroup) { defer wg.Done() c := make(chan tutum.Event) e := make(chan error) nodes.DiscoverPeers() go tutum.TutumEvents(c, e) tutumEventHandler(wg, c, e) }