package db

import "time"

// StartCheckConnection 自动重连数据库(5S), dbType = 0 - oracle; 1 - mysql; 2 - mongodb
func StartCheckConnection(dbType int) {
	switch dbType {
	case 0: // oracle
		for {
			if err := GetEngine().Ping(); err != nil {
				InitDbEngine()
			}
			time.Sleep(time.Duration(5000) * time.Millisecond)
		}
	case 1: // mysql
		for {
			if err := GetMySQLEngine().Ping(); err != nil {
				InitMySQLDbEngine()
			}
			time.Sleep(time.Duration(5000) * time.Millisecond)
		}
	case 2: // mongodb
		for {
			if err := GetMongoDB().Session.Ping(); err != nil {
				InitMongoDB()
			}
			time.Sleep(time.Duration(5000) * time.Millisecond)
		}
	}
}
