コード例 #1
0
ファイル: fsm.go プロジェクト: jgcsco/spigo
// Shutdown fsm and pirates
func shutdown() {
	var msg gotocol.Message
	hist := collect.NewHist("fsm")
	// wait until the delay has finished
	if archaius.Conf.RunDuration >= time.Millisecond {
		time.Sleep(archaius.Conf.RunDuration)
	}
	log.Println("fsm: Shutdown")
	for _, noodle := range noodles {
		gotocol.Message{gotocol.Goodbye, nil, time.Now(), gotocol.NilContext, "beer volcano"}.GoSend(noodle)
	}
	for len(noodles) > 0 {
		msg = <-listener
		collect.Measure(hist, time.Since(msg.Sent))
		if archaius.Conf.Msglog {
			log.Printf("fsm: %v\n", msg)
		}
		switch msg.Imposition {
		case gotocol.Goodbye:
			delete(noodles, msg.Intention)
			if archaius.Conf.Msglog {
				log.Printf("fsm: Pirate population: %v    \n", len(noodles))
			}
		}
	}
	collect.Save()
	log.Println("fsm: Exit")
}
コード例 #2
0
ファイル: asgard.go プロジェクト: jgcsco/spigo
// Run architecture for a while then shut down
func Run(rootservice, victim string) {
	// tell denominator to start chatting with microservices every 0.01 secs by default
	delay := archaius.Key(archaius.Conf, "chat")
	if delay == "" {
		delay = fmt.Sprintf("%dms", 10)
	}
	log.Println(rootservice+" activity rate ", delay)
	SendToName(rootservice, gotocol.Message{gotocol.Chat, nil, time.Now(), gotocol.NilContext, delay})
	// wait until the delay has finished
	if archaius.Conf.RunDuration >= time.Millisecond {
		time.Sleep(archaius.Conf.RunDuration / 2)
		chaosmonkey.Delete(&noodles, victim) // kill a random victim half way through
		time.Sleep(archaius.Conf.RunDuration / 2)
	}
	log.Println("asgard: Shutdown")
	ShutdownNodes()
	ShutdownEureka()
	collect.Save()
}