This commit is contained in:
2026-08-16 01:19:10 +08:00
parent c4b114762b
commit c554152f4f
43 changed files with 1311 additions and 318 deletions
+9 -7
View File
@@ -91,8 +91,8 @@ type TaskRuntime interface {
TriggerID(context.Context, uint) error
NextRuns() map[uint]time.Time
Reload(context.Context) error
Subscribe() chan []byte
Unsubscribe(chan []byte)
Subscribe(uint) chan []byte
Unsubscribe(uint, chan []byte)
}
type TaskUsecase struct{ TaskRepo }
@@ -115,7 +115,7 @@ func (uc *TaskUsecase) Validate(value *TimedTask) error {
switch value.ExecutorType {
case TaskExecutorMethod:
if !registeredTaskMethod(value.MethodName) {
return errors.New("方法未注册")
return fmt.Errorf("方法 %s 未注册", value.MethodName)
}
if len(value.Params) > 0 && !json.Valid(value.Params) {
return errors.New("params 必须是合法 JSON")
@@ -128,7 +128,7 @@ func (uc *TaskUsecase) Validate(value *TimedTask) error {
if len(value.HTTPHeader) > 0 {
headers := map[string]string{}
if json.Unmarshal(value.HTTPHeader, &headers) != nil {
return errors.New("httpHeader 必须是 JSON 对象")
return errors.New(`httpHeader 必须是 {"Key":"Value"} 形式的 JSON 对象`)
}
}
default:
@@ -229,7 +229,9 @@ func (uc *TaskApplicationUsecase) Reload(ctx context.Context) error {
return uc.runtime.Reload(ctx)
}
func (uc *TaskApplicationUsecase) Subscribe() chan []byte { return uc.runtime.Subscribe() }
func (uc *TaskApplicationUsecase) Unsubscribe(events chan []byte) {
uc.runtime.Unsubscribe(events)
func (uc *TaskApplicationUsecase) Subscribe(userID uint) chan []byte {
return uc.runtime.Subscribe(userID)
}
func (uc *TaskApplicationUsecase) Unsubscribe(userID uint, events chan []byte) {
uc.runtime.Unsubscribe(userID, events)
}