提交 265017da authored 作者: mooncake9527's avatar mooncake9527

update

上级 c95efefe
......@@ -51,7 +51,7 @@ func (l *logger) Error(format string, a ...interface{}) {
}
// 自定义中间件
func customMiddleware(tf xxl.TaskFunc) xxl.TaskFunc {
func customMiddleware(tf xxl.TaskFn) xxl.TaskFn {
return func(cxt context.Context, param *xxl.RunReq) string {
log.Println("I am a middleware start")
res := tf(cxt, param)
......
......@@ -23,7 +23,7 @@ type Executor interface {
// Use 使用中间件
Use(middlewares ...Middleware)
// RegTask 注册任务
RegTask(pattern string, task TaskFunc)
RegTask(pattern string, task TaskFn)
// RunTask 运行任务
RunTask(writer http.ResponseWriter, request *http.Request)
// KillTask 杀死任务
......@@ -119,7 +119,7 @@ func (e *executor) Stop() {
}
// RegTask 注册任务
func (e *executor) RegTask(pattern string, task TaskFunc) {
func (e *executor) RegTask(pattern string, task TaskFn) {
var t = &Task{}
t.fn = e.chain(task)
e.regList.Set(pattern, t)
......
package xxl
// Middleware 中间件构造函数
type Middleware func(TaskFunc) TaskFunc
type Middleware func(TaskFn) TaskFn
func (e *executor) chain(next TaskFunc) TaskFunc {
func (e *executor) chain(next TaskFn) TaskFn {
for i := range e.middlewares {
next = e.middlewares[len(e.middlewares)-1-i](next)
}
......
......@@ -6,16 +6,14 @@ import (
"runtime/debug"
)
// TaskFunc 任务执行函数
type TaskFunc func(cxt context.Context, param *RunReq) string
type TaskFn func(ctx context.Context, param *RunReq) string
// Task 任务
type Task struct {
Id int64
Name string
Ext context.Context
Param *RunReq
fn TaskFunc
fn TaskFn
Cancel context.CancelFunc
StartTime int64
EndTime int64
......@@ -23,7 +21,6 @@ type Task struct {
log Logger
}
// Run 运行任务
func (t *Task) Run(callback func(code int64, msg string)) {
defer func(cancel func()) {
if err := recover(); err != nil {
......@@ -35,10 +32,8 @@ func (t *Task) Run(callback func(code int64, msg string)) {
}(t.Cancel)
msg := t.fn(t.Ext, t.Param)
callback(SuccessCode, msg)
return
}
// Info 任务信息
func (t *Task) Info() string {
return fmt.Sprintf("任务ID[%d]任务名称[%s]参数:%s", t.Id, t.Name, t.Param.ExecutorParams)
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论