diff --git a/define.go b/define.go index 6e7b078..bd1667a 100644 --- a/define.go +++ b/define.go @@ -19,6 +19,10 @@ type Config struct { ForbiddenCallback bool // Param 任务执行参数 Param map[string]interface{} + // TaskName 任务名称 + TaskName string + // Async 是否异步 + Async bool } // Result 执行结果 diff --git a/task.go b/task.go index b49e528..c9d5ddc 100644 --- a/task.go +++ b/task.go @@ -109,7 +109,6 @@ func (d *dispatch) Run(ctx context.Context, cfg *Config) *Result { TaskConfig: cfg, Data: nil, Err: nil, - Async: cfg.Async, } defer func() { result.FinishTime = time.Now().UnixNano() @@ -120,8 +119,6 @@ func (d *dispatch) Run(ctx context.Context, cfg *Config) *Result { result.Err = fmt.Errorf("%v 任务未注册", cfg.TaskName) } d.lock.RUnlock() - result.TaskRunID = taskInstance.GetRunID() - result.TaskDescription = taskInstance.Description() if cfg.Async { // 异步运行 go func() { @@ -133,11 +130,15 @@ func (d *dispatch) Run(ctx context.Context, cfg *Config) *Result { result.Err = fmt.Errorf("出现其他场景Panic : %v", e) } } - result.Data, result.Err = taskInstance.Execute(ctx, cfg) + result = taskInstance.Execute(ctx, cfg) + result.TaskRunID = taskInstance.GetRunID() + result.TaskDescription = taskInstance.Description() _ = taskInstance.Callback(result) }() } else { - result.Data, result.Err = taskInstance.Execute(ctx, cfg) + result = taskInstance.Execute(ctx, cfg) + result.TaskRunID = taskInstance.GetRunID() + result.TaskDescription = taskInstance.Description() _ = taskInstance.Callback(result) } return result