github.com/benz9527/xboot@v0.0.0-20240504061247-c23f15593274/timer/stats_others.go (about) 1 //go:build !windows 2 // +build !windows 3 4 package timer 5 6 import ( 7 "context" 8 ) 9 10 func jobStatsWrapper(stats *xTimingWheelsStats, invoke Job) Job { 11 if stats == nil { 12 return invoke 13 } 14 return func(ctx context.Context, metadata JobMetadata) { 15 var beginTime = stats.clock.NowInDefaultTZ() 16 defer func() { 17 stats.IncreaseJobExecutedCount() 18 stats.RecordJobExecuteDuration(stats.clock.Since(beginTime).Milliseconds()) 19 }() 20 stats.RecordJobLatency(beginTime.UnixMilli() - metadata.GetExpiredMs()) 21 invoke(ctx, metadata) 22 } 23 }