refactor(bootstrap): move runtime init from router to cmd layer

Extract SyncEvents and InitLogWriter from router.Serve into bootstrap.Init
called from cmd entry points with trace-aware context. Preserve existing
Register* wiring for task and push domain integrations.
This commit is contained in:
ryan
2026-06-18 10:38:08 +08:00
parent 50c45db561
commit 03fa5d948d
9 changed files with 152 additions and 15 deletions
+3
View File
@@ -9,6 +9,7 @@ import (
"log"
"sync"
"github.com/Rain-kl/Wavelet/internal/bootstrap"
"github.com/Rain-kl/Wavelet/internal/router"
"github.com/Rain-kl/Wavelet/internal/task/scheduler"
"github.com/Rain-kl/Wavelet/internal/task/worker"
@@ -20,6 +21,8 @@ var allCmd = &cobra.Command{
Short: "以融合模式同时启动 API、Worker 和 Scheduler",
Run: func(_ *cobra.Command, _ []string) {
log.Println("[All] 融合模式启动")
bootstrap.RegisterAll()
runBootstrap(bootstrap.Options{API: true})
var wg sync.WaitGroup
+3
View File
@@ -5,6 +5,7 @@
package cmd
import (
"github.com/Rain-kl/Wavelet/internal/bootstrap"
"github.com/Rain-kl/Wavelet/internal/router"
"github.com/spf13/cobra"
)
@@ -13,6 +14,8 @@ var apiCmd = &cobra.Command{
Use: "api",
Short: "wavelet API",
Run: func(_ *cobra.Command, _ []string) {
bootstrap.RegisterAPI()
runBootstrap(bootstrap.Options{API: true})
router.Serve()
},
}
+17
View File
@@ -0,0 +1,17 @@
// Copyright 2026 Arctel.net
// SPDX-License-Identifier: Apache-2.0
package cmd
import (
"context"
"github.com/Rain-kl/Wavelet/internal/bootstrap"
"github.com/Rain-kl/Wavelet/pkg/trace"
)
func runBootstrap(opts bootstrap.Options) {
ctx, span := trace.Start(context.Background(), "bootstrap.Init")
defer span.End()
bootstrap.Init(ctx, opts)
}
+2
View File
@@ -7,6 +7,7 @@ package cmd
import (
"log"
"github.com/Rain-kl/Wavelet/internal/bootstrap"
"github.com/Rain-kl/Wavelet/internal/task/scheduler"
"github.com/spf13/cobra"
@@ -16,6 +17,7 @@ var schedulerCmd = &cobra.Command{
Use: "scheduler",
Short: "wavelet Scheduler",
Run: func(_ *cobra.Command, _ []string) {
runBootstrap(bootstrap.Options{})
log.Println("[Scheduler] 启动定时任务调度服务")
if err := scheduler.StartScheduler(); err != nil {
log.Fatalf("[调度器] 启动失败: %v", err)
+2
View File
@@ -7,6 +7,7 @@ package cmd
import (
"log"
"github.com/Rain-kl/Wavelet/internal/bootstrap"
"github.com/Rain-kl/Wavelet/internal/task/worker"
"github.com/spf13/cobra"
@@ -16,6 +17,7 @@ var workerCmd = &cobra.Command{
Use: "worker",
Short: "wavelet Worker",
Run: func(_ *cobra.Command, _ []string) {
runBootstrap(bootstrap.Options{})
log.Println("[Worker] 启动任务处理服务")
if err := worker.StartWorker(); err != nil {
log.Fatalf("[工作器] 启动失败: %v", err)