JCC-CSScheduler/common/pkgs/mq/advisor/task/task.go

49 lines
1.4 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package task
import (
"gitlink.org.cn/cloudream/common/pkgs/mq"
"gitlink.org.cn/cloudream/common/pkgs/types"
myreflect "gitlink.org.cn/cloudream/common/utils/reflect"
)
// 任务。
// 由于json-iter库的缺陷这个类型名必须加一点前缀否则会和executor中的重名导致代码异常
type AdvTaskInfo interface {
Noop()
}
// 增加了新类型后需要在这里也同步添加
var TaskInfoTypeUnion = types.NewTypeUnion[AdvTaskInfo]()
type TaskInfoBase struct{}
func (s *TaskInfoBase) Noop() {}
// 任务上报的状态
// 由于json-iter库的缺陷这个类型名必须加一点前缀否则会和executor中的重名导致代码异常
type AdvTaskStatus interface {
Noop()
}
// 增加了新类型后需要在这里也同步添加
var TaskStatusTypeUnion = types.NewTypeUnion[AdvTaskStatus]()
type TaskStatusBase struct{}
func (s *TaskStatusBase) Noop() {}
// 注此函数必须以var _ = Register[xxx, xxx]()的形式被调用这样才能保证init中RegisterUnionType时
// TypeUnion不是空的。因为包级变量初始化比init函数调用先进行
func Register[TTaskInfo AdvTaskInfo, TTaskStatus AdvTaskStatus]() any {
TaskInfoTypeUnion.Add(myreflect.TypeOf[TTaskInfo]())
TaskStatusTypeUnion.Add(myreflect.TypeOf[TTaskStatus]())
return nil
}
func init() {
mq.RegisterUnionType(TaskInfoTypeUnion)
mq.RegisterUnionType(TaskStatusTypeUnion)
}