修复重复注册问题

This commit is contained in:
ryan
2026-06-11 09:03:24 +08:00
parent 3023d47eec
commit c1a1904a67
5 changed files with 39 additions and 3 deletions
+1 -1
View File
@@ -5356,7 +5356,7 @@ const docTemplate = `{
"type": "boolean"
},
"Type": {
"description": "类型:string, text, number",
"description": "类型:string, text, number, boolean",
"type": "string"
}
}
+1 -1
View File
@@ -5349,7 +5349,7 @@
"type": "boolean"
},
"Type": {
"description": "类型:string, text, number",
"description": "类型:string, text, number, boolean",
"type": "string"
}
}
+1 -1
View File
@@ -764,7 +764,7 @@ definitions:
description: 是否必填
type: boolean
Type:
description: 类型:string, text, number
description: 类型:string, text, number, boolean
type: string
type: object
task.UpdateScheduleRequest:
+5
View File
@@ -43,6 +43,11 @@ var (
func RegisterTaskMeta(meta TaskMeta) {
dispatchableTasksMutex.Lock()
defer dispatchableTasksMutex.Unlock()
for _, t := range dispatchableTasks {
if t.Type == meta.Type {
return
}
}
dispatchableTasks = append(dispatchableTasks, meta)
}
+31
View File
@@ -0,0 +1,31 @@
// Copyright 2026 Arctel.net
// SPDX-License-Identifier: Apache-2.0
package task_test
import (
"testing"
"github.com/Rain-kl/Wavelet/internal/task"
taskhandlers "github.com/Rain-kl/Wavelet/internal/task/handlers"
)
func TestDuplicateTaskMeta(t *testing.T) {
// Call Register twice to simulate being imported by multiple packages (routers, worker, etc.)
taskhandlers.Register()
taskhandlers.Register()
metas := task.GetDispatchableTasks()
// Check if we have duplicates by checking if a Type appears more than once
seen := make(map[string]int)
for _, m := range metas {
seen[m.Type]++
}
for taskType, count := range seen {
if count > 1 {
t.Errorf("Task type %q registered %d times, expected at most 1", taskType, count)
}
}
}