mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-09-29 22:06:38 +08:00
修复重复注册问题
This commit is contained in:
+1
-1
@@ -5356,7 +5356,7 @@ const docTemplate = `{
|
||||
"type": "boolean"
|
||||
},
|
||||
"Type": {
|
||||
"description": "类型:string, text, number",
|
||||
"description": "类型:string, text, number, boolean",
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -5349,7 +5349,7 @@
|
||||
"type": "boolean"
|
||||
},
|
||||
"Type": {
|
||||
"description": "类型:string, text, number",
|
||||
"description": "类型:string, text, number, boolean",
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -764,7 +764,7 @@ definitions:
|
||||
description: 是否必填
|
||||
type: boolean
|
||||
Type:
|
||||
description: 类型:string, text, number
|
||||
description: 类型:string, text, number, boolean
|
||||
type: string
|
||||
type: object
|
||||
task.UpdateScheduleRequest:
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user