refactor(task): replace init registration with bootstrap wiring

Introduce internal/bootstrap as the composition root with sync.Once
guards for task handler registration and push listener wiring. Replace
the single OnTaskCompleted global hook with multi-subscriber handlers
and remove init()-driven side effects from worker, admin task, and push.
This commit is contained in:
ryan
2026-06-18 10:34:49 +08:00
parent 6066eb114b
commit 22c2ad5c73
8 changed files with 99 additions and 21 deletions
+2 -6
View File
@@ -7,22 +7,18 @@ package worker
import (
"time"
"github.com/Rain-kl/Wavelet/internal/bootstrap"
"github.com/Rain-kl/Wavelet/internal/config"
"github.com/Rain-kl/Wavelet/internal/task"
taskhandlers "github.com/Rain-kl/Wavelet/internal/task/handlers"
"github.com/hibiken/asynq"
)
// workerShutdownTimeout Worker 优雅关闭超时时间
const workerShutdownTimeout = 3 * time.Minute
func init() {
// 注册所有任务处理器
taskhandlers.Register()
}
// StartWorker 启动任务处理服务器
func StartWorker() error {
bootstrap.RegisterWorker()
asynqServer := asynq.NewServer(
task.RedisOpt,
asynq.Config{