Skip to content

Commit

Permalink
新增:task的消费链路追踪入口
Browse files Browse the repository at this point in the history
  • Loading branch information
steden committed Oct 19, 2023
1 parent 2dc69b7 commit 48267f4
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion run.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package tasks

import (
"context"
"github.com/farseer-go/fs/container"
"github.com/farseer-go/fs/exception"
"github.com/farseer-go/fs/flog"
"github.com/farseer-go/fs/stopwatch"
"github.com/farseer-go/fs/trace"
"time"
)

Expand Down Expand Up @@ -56,6 +58,7 @@ func RunNow(taskName string, interval time.Duration, taskFn func(context *TaskCo
func runTask(taskName string, interval time.Duration, taskFn func(context *TaskContext)) (nextInterval time.Duration) {
// 这里需要提前设置默认的间隔时间。如果发生异常时,不提前设置会=0
nextInterval = interval
entryTask := container.Resolve[trace.IManager]().EntryTask(taskName)
try := exception.Try(func() {
taskContext := &TaskContext{
sw: stopwatch.StartNew(),
Expand All @@ -67,7 +70,8 @@ func runTask(taskName string, interval time.Duration, taskFn func(context *TaskC
}
})
try.CatchException(func(exp any) {
_ = flog.Errorf("[%s] throw exception:%s", taskName, exp)
entryTask.Error(flog.Errorf("[%s] throw exception:%s", taskName, exp))
})
entryTask.End()
return
}

0 comments on commit 48267f4

Please sign in to comment.