优化结构
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
taskbiz "kra/internal/biz/task"
|
||||
|
||||
"kra/internal/config"
|
||||
taskmodule "kra/internal/modules/task"
|
||||
platformtask "kra/pkg/task"
|
||||
)
|
||||
|
||||
@@ -27,8 +28,12 @@ func (methods *TaskMethods) RegisterTasks(registry *platformtask.Registry) {
|
||||
if methods == nil || registry == nil {
|
||||
return
|
||||
}
|
||||
descriptions := map[string]string{}
|
||||
for _, task := range taskmodule.TimedTasks() {
|
||||
descriptions[task.MethodName] = task.Description
|
||||
}
|
||||
registry.Register(platformtask.Method{
|
||||
Name: taskbiz.TaskMethodClearDB, Description: "清理数据库过期日志(操作记录/JWT黑名单/定时任务执行日志)", Run: func(ctx context.Context, _ json.RawMessage) error {
|
||||
Name: taskbiz.TaskMethodClearDB, Description: descriptions[taskbiz.TaskMethodClearDB], Run: func(ctx context.Context, _ json.RawMessage) error {
|
||||
if ctx == nil {
|
||||
ctx = context.Background()
|
||||
}
|
||||
@@ -42,7 +47,7 @@ func (methods *TaskMethods) RegisterTasks(registry *platformtask.Registry) {
|
||||
},
|
||||
})
|
||||
registry.Register(platformtask.Method{
|
||||
Name: taskbiz.TaskMethodUploads, Description: "清理过期大文件上传会话", Run: func(ctx context.Context, _ json.RawMessage) error {
|
||||
Name: taskbiz.TaskMethodUploads, Description: descriptions[taskbiz.TaskMethodUploads], Run: func(ctx context.Context, _ json.RawMessage) error {
|
||||
if ctx == nil {
|
||||
ctx = context.Background()
|
||||
}
|
||||
|
||||
@@ -219,7 +219,7 @@ func TestAutomaticAndManualTriggersShareOverlapGate(t *testing.T) {
|
||||
case <-time.After(time.Second):
|
||||
t.Fatal("automatic task execution did not start")
|
||||
}
|
||||
if scheduler.Trigger(task) {
|
||||
if scheduler.trigger(task) {
|
||||
t.Fatal("manual trigger bypassed an active automatic execution")
|
||||
}
|
||||
if got := calls.Load(); got != 1 {
|
||||
|
||||
@@ -402,7 +402,7 @@ func (s *TaskScheduler) TriggerID(ctx context.Context, id uint) error {
|
||||
if task == nil {
|
||||
return errors.New("任务不存在")
|
||||
}
|
||||
if !s.Trigger(task) {
|
||||
if !s.trigger(task) {
|
||||
return errors.New("任务正在执行或调度器正在停止")
|
||||
}
|
||||
return nil
|
||||
@@ -422,7 +422,7 @@ func (s *TaskScheduler) NextRuns() map[uint]time.Time {
|
||||
return out
|
||||
}
|
||||
|
||||
func (s *TaskScheduler) Trigger(task *taskbiz.TimedTask) bool {
|
||||
func (s *TaskScheduler) trigger(task *taskbiz.TimedTask) bool {
|
||||
if task == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user