Selaa lähdekoodia

修改 MongoDB Ping 逻辑 BUG

muchinfo 3 kuukautta sitten
vanhempi
commit
a646273c51
2 muutettua tiedostoa jossa 8 lisäystä ja 2 poistoa
  1. 1 1
      db/checkConnection.go
  2. 7 1
      db/mongodb.go

+ 1 - 1
db/checkConnection.go

@@ -33,7 +33,7 @@ func StartCheckConnection(dbType int) {
 		}
 	case 2: // mongodb
 		for {
-			if err := GetMongoDBClient().Ping(int64(10 * time.Second)); err != nil {
+			if err := GetMongoDBClient().Ping(10); err != nil {
 				InitMongoDB()
 			}
 			fDelay()

+ 7 - 1
db/mongodb.go

@@ -67,10 +67,16 @@ func InitMongoDB() error {
 		config.SerCfg.GetMongoDBPort(),
 		config.SerCfg.GetMongoDBDBName(),
 	)
-	client, err = qmgo.NewClient(ctx, &qmgo.Config{Uri: u})
+	c, err := qmgo.NewClient(ctx, &qmgo.Config{Uri: u})
 	if err != nil {
 		return err
 	}
+
+	if err = c.Ping(10); err != nil {
+		return err
+	}
+
+	client = c
 	db = client.Database(config.SerCfg.GetMongoDBDBName())
 
 	return nil