Browse Source

refactor: user init and update boot sequence #1203

Jacky 1 day ago
parent
commit
6c62725d7c
2 changed files with 14 additions and 6 deletions
  1. 11 3
      internal/kernel/boot.go
  2. 3 3
      internal/kernel/init_user.go

+ 11 - 3
internal/kernel/boot.go

@@ -67,17 +67,25 @@ func Boot(ctx context.Context) {
 
 func InitAfterDatabase(ctx context.Context) {
 	syncs := []func(ctx context.Context){
+		InitUser,
 		registerPredefinedUser,
+		cluster.RegisterPredefinedNodes,
+		RegisterAcmeUser,
+	}
+
+	for _, v := range syncs {
+		v(ctx)
+	}
+
+	asyncs := []func(ctx context.Context){
 		cert.InitRegister,
 		cron.InitCronJobs,
-		cluster.RegisterPredefinedNodes,
 		analytic.RetrieveNodesStatus,
 		passkey.Init,
-		RegisterAcmeUser,
 		mcp.Init,
 	}
 
-	for _, v := range syncs {
+	for _, v := range asyncs {
 		go v(ctx)
 	}
 }

+ 3 - 3
internal/kernel/init_user.go

@@ -7,8 +7,8 @@ import (
 	"github.com/uozi-tech/cosy"
 )
 
-func InitUser() {
-	db := cosy.UseDB(context.Background())
+func InitUser(ctx context.Context) {
+	db := cosy.UseDB(ctx)
 	user := &model.User{}
 	db.Unscoped().Where("id = ?", 1).Find(user)
 
@@ -20,7 +20,7 @@ func InitUser() {
 			},
 			Name: "admin",
 		})
-		return 
+		return
 	}
 
 	// if user is found, check if the user is deleted