Пример #1
0
func setUp(t *testing.T) {
	var err error
	cfgTest, err = config.ReadConfig("gridas_test.yaml")
	if err != nil {
		t.Fatal("setUp:", err)
	}
	t.Logf("test configuration: %+v\n", cfgTest)
	sessionTest, err = mgo.Dial(cfgTest.Mongo)
	if err != nil {
		t.Fatal("setUp:", err)
	}
	sessionTest.SetMode(mgo.Monotonic, true)
	databaseTest = sessionTest.DB(cfgTest.Database)

}
Пример #2
0
func main() {
	var cfgFile = flag.String("config", "./gridas.yaml", "configuration file")
	flag.Parse()
	cfg, err := config.ReadConfig(*cfgFile)
	if err != nil {
		mylog.Alert(err)
		os.Exit(-1)
	}
	fmt.Printf("configuration %q %+v\n", *cfgFile, cfg)

	mylog.SetLevel(cfg.LogLevel)
	mylog.Alert("hello World!")
	reqChan := make(chan *gridas.Petition, cfg.QueueSize)
	session, err := mgo.Dial(cfg.Mongo)
	if err != nil {
		mylog.Alert(err)
		panic(err)
	}
	defer func() {
		session.Close()
		mylog.Debugf("mongo session closed %+v", session)
	}()

	mylog.Debugf("mongo session %+v", session)

	db := session.DB(cfg.Database)
	mylog.Debug("mongo database", db)
	listener := &gridas.Listener{SendTo: reqChan, Cfg: cfg, SessionSeed: session}
	mylog.Debugf("listener %+v", listener)
	consumer := &gridas.Consumer{GetFrom: reqChan, Cfg: cfg, SessionSeed: session}
	mylog.Debugf("consumer %+v", consumer)
	rplyr := &gridas.Replyer{Cfg: cfg, SessionSeed: session}
	mylog.Debugf("replyer %+v", rplyr)
	rcvr := &gridas.Recoverer{SendTo: reqChan, Cfg: cfg, SessionSeed: session}
	mylog.Debugf("recoverer %+v", rcvr)
	endConsumers := consumer.Start(cfg.Consumers)
	if err := rcvr.Recover(); err != nil {
		mylog.Alert(err)
		os.Exit(-1)
	}
	http.Handle("/", listener)
	http.Handle("/responses/", http.StripPrefix("/responses/", rplyr))
	go func() {
		mylog.Debug("starting HTTP server (listener)")
		err := http.ListenAndServe(":"+cfg.Port, nil)
		if err != nil {
			mylog.Alert(err)
			os.Exit(-1)
		}
	}()

	onEnd(func() {
		mylog.Info("shutting down gridas ...")
		listener.Stop()
		mylog.Debug("listener stopped")
		consumer.Stop()
		mylog.Debug("consumer stopped")
	})
	<-endConsumers
	mylog.Alert("bye World!")
}