Exemple #1
0
func init() {
	revel.OnAppStart(func() {
		// 为了避免在多个app 同时运行.
		if isRunning {
			return
		}
		childProcessName := plugins.GetArg("-server")
		if childProcessName != "GoMysqlProxy" {
			return
		}

		// loade the hosts in the config
		host.Groups = getHostConfig()
		host.Hosts = getAllHosts()

		// set mysql connection pooling params.
		pooling.MinPoolingConnection = revel.Config.IntDefault("mysql.ConnectionPooling.min", 10)
		pooling.MaxPoolingConnection = revel.Config.IntDefault("mysql.ConnectionPooling.max", 20)

		// init the main mysql proxy object.
		models.MyProxy = models.NewMysqlProxy()

		wg := &sync.WaitGroup{}
		wg.Add(1)

		cron := cron.New()
		cron.AddFunc("@every 10s", func() { host.GetAndLogHostStatus() })
		cron.Start()
		isRunning = true
	})
}
Exemple #2
0
func NewMysqlProxy() *MysqlProxy {
	proxy := &MysqlProxy{}

	proxy.Init()

	host.GetAndLogHostStatus()

	return proxy
}