コード例 #1
0
ファイル: start.go プロジェクト: vrecan/gomasticate
//Run the app.
func Run() (err error) {
	var wg sync.WaitGroup
	log.Info("Starting gomasticate")
	conf, err := NewConf("conf.yaml")
	if nil != err {
		log.Error(err)
		return
	}
	log.Info(conf)
	chewChan := make(chan *messaging.Food, 2000)
	swallowChan := make(chan *messaging.Food, 4000)

	done := make(chan interface{})

	wg.Add(2)
	go lips.OpenWide(chewChan, done, &wg, conf.LipsPort())
	go chew.Chew(chewChan, swallowChan, &wg)

	sw := swallow.NewSwallow(conf.EsHost(), swallowChan, 10)

	//handle signals
	c := make(chan os.Signal, 1)
	s := make(chan int, 1)
	signal.Notify(c)
	go Death(c, s)
	death := <-s //time for shutdown
	log.Debug("Death return code: ", death)
	close(done)
	sw.Close()
	log.Info("Waiting for goroutines to finish...")
	wg.Wait()
	log.Info("Exiting")
	return
}
コード例 #2
0
ファイル: lips_test.go プロジェクト: vrecan/gomasticate
		msg.Priority = &priority
		msg.Severity = &severity

		food.Rfc3164 = append(food.Rfc3164, msg)
		chewChan = make(chan *messaging.Food, 100) //blocking
		done = make(chan interface{})

	})

	It("Test simple message through the lips", func() {
		msgCount := 10
		var wg sync.WaitGroup
		tot := make(chan int)
		wg.Add(1)
		go lips.PusherProto(msgCount, tot, food, lipsPort)
		go lips.OpenWide(chewChan, done, &wg, lipsPort)
		log.Info("Waiting for sends to be finished")
		count := <-tot //sync until it's been sent
		Expect(count).Should(Equal(msgCount))

		rcvCount := 0
		log.Info("Receiving msgs")
		for _ = range chewChan {
			rcvCount++
			if rcvCount >= 10 {
				break
			}
		}
		Expect(len(chewChan)).Should(Equal(0))
		close(done)
		log.Info("Waiting for shutdown")