46 lines
1.1 KiB
Go
46 lines
1.1 KiB
Go
package task
|
||
|
||
import (
|
||
"gitlink.org.cn/cloudream/common/pkgs/types"
|
||
"gitlink.org.cn/cloudream/common/utils/reflect2"
|
||
"gitlink.org.cn/cloudream/common/utils/serder"
|
||
)
|
||
|
||
// 任务
|
||
type TaskInfo interface {
|
||
Noop()
|
||
}
|
||
|
||
// 增加了新类型后需要在这里也同步添加
|
||
var TaskInfoTypeUnion = serder.UseTypeUnionExternallyTagged(types.Ref(types.NewTypeUnion[TaskInfo]()))
|
||
|
||
type TaskInfoBase struct{}
|
||
|
||
func (s *TaskInfoBase) Noop() {}
|
||
|
||
// 任务上报的状态
|
||
type TaskStatus interface {
|
||
Noop()
|
||
}
|
||
|
||
// 增加了新类型后需要在这里也同步添加
|
||
var TaskStatusTypeUnion = serder.UseTypeUnionExternallyTagged(types.Ref(types.NewTypeUnion[TaskStatus]()))
|
||
|
||
type TaskStatusBase struct{}
|
||
|
||
func (s *TaskStatusBase) Noop() {}
|
||
|
||
// 只能在init函数中调用,因为包级变量初始化会比init函数调用先进行
|
||
func Register[TTaskInfo TaskInfo, TTaskStatus TaskStatus]() any {
|
||
TaskInfoTypeUnion.Add(reflect2.TypeOf[TTaskInfo]())
|
||
|
||
TaskStatusTypeUnion.Add(reflect2.TypeOf[TTaskStatus]())
|
||
|
||
return nil
|
||
}
|
||
|
||
type TaskOperateInfo struct {
|
||
TaskID string
|
||
Command string
|
||
}
|