Example #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
	})
}
Example #2
0
func init() {
    // to maintance the session cache
    revel.OnAppStart(func() {
        staticTotal := uploader.GetParamString("static.host.total", "0")
        if staticTotal != "0" {
            uploader.GetAllStaticHosts()
            cron := cron.New()
            cron.AddFunc("@every 1s", func() {
                uploader.SyncNewToAllStaticHosts()
            })
            cron.AddFunc("@every 10s", func() {
                uploader.TrySyncFailedStatic()
            })
            cron.Start()
        }
    })
}
Example #3
0
func init() {
	revel.OnAppStart(func() {
		// 为了避免在多个app 同时
		if isRunning {
			return
		}
		childProcessName := plugins.GetArg("-server")
		if childProcessName != "HostTracker" {
			return
		}

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

		cron := cron.New()
		cron.AddFunc("@every 30s", func() { modules.Run() })
		cron.Start()
		isRunning = true
	})
}