fix
This commit is contained in:
parent
dcd2281f33
commit
87f8651bed
@ -19,6 +19,10 @@ type Config struct {
|
||||
ForbiddenCallback bool
|
||||
// Param 任务执行参数
|
||||
Param map[string]interface{}
|
||||
// TaskName 任务名称
|
||||
TaskName string
|
||||
// Async 是否异步
|
||||
Async bool
|
||||
}
|
||||
|
||||
// Result 执行结果
|
||||
|
11
task.go
11
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
|
||||
|
Loading…
Reference in New Issue
Block a user