コード例 #1
0
ファイル: init.go プロジェクト: nangong92t/go_src
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
	})
}
コード例 #2
0
ファイル: plugin.go プロジェクト: nangong92t/go_src
func init() {
	MainCron = cron.New()
	revel.OnAppStart(func() {
		if size := revel.Config.IntDefault("jobs.pool", DEFAULT_JOB_POOL_SIZE); size > 0 {
			workPermits = make(chan struct{}, size)
		}
		selfConcurrent = revel.Config.BoolDefault("jobs.selfconcurrent", false)
		MainCron.Start()
		fmt.Println("Go to /@jobs to see job status.")
	})
}
コード例 #3
0
ファイル: init.go プロジェクト: nangong92t/go_src
func init() {
	revel.OnAppStart(func() {
		// Set the default expiration time.
		defaultExpiration := time.Hour // The default for the default is one hour.
		if expireStr, found := revel.Config.String("cache.expires"); found {
			var err error
			if defaultExpiration, err = time.ParseDuration(expireStr); err != nil {
				panic("Could not parse default cache expiration duration " + expireStr + ": " + err.Error())
			}
		}

		// make sure you aren't trying to use both memcached and redis
		if revel.Config.BoolDefault("cache.memcached", false) && revel.Config.BoolDefault("cache.redis", false) {
			panic("You've configured both memcached and redis, please only include configuration for one cache!")
		}

		// Use memcached?
		if revel.Config.BoolDefault("cache.memcached", false) {
			hosts := strings.Split(revel.Config.StringDefault("cache.hosts", ""), ",")
			if len(hosts) == 0 {
				panic("Memcache enabled but no memcached hosts specified!")
			}

			Instance = NewMemcachedCache(hosts, defaultExpiration)
			return
		}

		// Use Redis (share same config as memcached)?
		if revel.Config.BoolDefault("cache.redis", false) {
			hosts := strings.Split(revel.Config.StringDefault("cache.hosts", ""), ",")
			if len(hosts) == 0 {
				panic("Redis enabled but no Redis hosts specified!")
			}
			if len(hosts) > 1 {
				panic("Redis currently only supports one host!")
			}
			password := revel.Config.StringDefault("cache.redis.password", "")
			Instance = NewRedisCache(hosts[0], password, defaultExpiration)
			return
		}

		// By default, use the in-memory cache.
		Instance = NewInMemoryCache(defaultExpiration)
	})
}
コード例 #4
0
ファイル: init.go プロジェクト: nangong92t/go_src
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
	})
}
コード例 #5
0
ファイル: plugin.go プロジェクト: nangong92t/go_src
func init() {
	revel.OnAppStart(func() {
		fmt.Println("Go to /@tests to run the tests.")
	})
}