Пример #1
0
func boot() {
	var err error

	// log.SetOutput(os.Stdout)

	err = InitMySqlClient()
	if err != nil {
		Log.Error(err)
		os.Exit(0)
	}
	client := user.GetClient()
	users, err := client.GetUsers()
	if err != nil {
		Log.Error(err)
		os.Exit(0)
	}
	Log.Info(len(users))
	// clear storage
	// storage.ClearAll()
	bootUsers(users)
	time.Sleep(muconfig.Conf.Base.CheckTime * time.Second)

	go func() {
		for {
			go func() {
				// check users
				users, err = client.GetUsers()
				if err != nil {
					Log.Error(err)
					// os.Exit(0)
				}
				checkUsers(users)
				Log.Info("check finish...")
			}()
			time.Sleep(muconfig.Conf.Base.CheckTime * time.Second)
		}
	}()

	go func() {
		for {
			go func() {
				// check users
				users, err = client.GetUsers()
				if err != nil {
					Log.Error(err)
					// os.Exit(0)
				}
				syncUsers(users)
				Log.Info("sync finish...")
			}()
			time.Sleep(muconfig.Conf.Base.SyncTime * time.Second)
		}
	}()
}
Пример #2
0
func boot() {
	var err error

	// log.SetOutput(os.Stdout)

	switch muconfig.Conf.Base.Client {
	case "mysql":
		InitMySqlClient()
	case "webapi":
		InitWebApi()
	default:
		InitWebApi()
	}

	client := user.GetClient()
	users, err := client.GetUsers()
	if err != nil {
		Log.Error("Get User Error", err)
		os.Exit(0)
	}
	Log.Info(len(users))
	// clear storage
	storage.ClearAll()
	//bootUsers(users)
	//time.Sleep(muconfig.Conf.Base.CheckTime * time.Second)

	go func() {
		for {
			go func() {
				// check users
				users, err = client.GetUsers()
				if err != nil {
					Log.Error("Get User Error", err)
					// os.Exit(0)
				}
				Log.Debug(users)
				checkUsers(users)
				Log.Info("check finish...")
			}()
			time.Sleep(muconfig.Conf.Base.CheckTime * time.Second)
		}
	}()

	go func() {
		for {
			go func() {
				// sync users
				users, err = client.GetUsers()
				if err != nil {
					Log.Error(err)
					// os.Exit(0)
				}
				syncUsers(users)
				Log.Info("sync finish...start logging online count")
				err = client.LogNodeOnlineUser(storage.GetOnlineUsersCount(users))
				if err != nil {
					Log.Error(err)
				}

				err = client.UpdateNodeInfo()
				if err != nil {
					Log.Error(err)
				}

			}()
			time.Sleep(muconfig.Conf.Base.SyncTime * time.Second)
		}
	}()

}