Ejemplo n.º 1
0
func MustInitBongo(
	appName string,
	eventExchangeName string,
	c *Config,
	log logging.Logger,
	metrics *metrics.Metrics,
	debug bool,
) *bongo.Bongo {
	rmqConf := &rabbitmq.Config{
		Host:     c.Mq.Host,
		Port:     c.Mq.Port,
		Username: c.Mq.Login,
		Password: c.Mq.Password,
		Vhost:    c.Mq.Vhost,
	}

	bConf := &broker.Config{
		RMQConfig:    rmqConf,
		ExchangeName: eventExchangeName,
		QOS:          10,
	}

	db := MustInitDB(c, log, debug)

	broker := broker.New(appName, bConf, log)
	// set metrics for broker
	broker.Metrics = metrics

	bongo := bongo.New(broker, db, log)
	err := bongo.Connect()
	if err != nil {
		log.Fatal("Error while starting bongo, exiting err: %s", err.Error())
	}

	log.Info("Caching disabled: %v", c.DisableCaching)
	if !c.DisableCaching {
		redisConn, err := InitRedisConn(c)
		if err != nil {
			log.Critical("Bongo couldnt connect to redis, caching will not be available Err: %s", err.Error())
		} else {
			bongo.Cache = redisConn
		}
	}

	return bongo
}
Ejemplo n.º 2
0
func registerSignalHandler(l *asgd.LifeCycle, log logging.Logger) chan struct{} {
	done := make(chan struct{}, 1)

	go func() {
		signals := make(chan os.Signal, 1)
		signal.Notify(signals)

		signal := <-signals
		switch signal {
		case syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGSTOP, syscall.SIGKILL:
			log.Info("recieved exit signal, closing...")
			err := l.Close()
			if err != nil {
				log.Critical(err.Error())
			}
			close(done)
		}

	}()
	return done
}