73 lines
1.6 KiB
Go
73 lines
1.6 KiB
Go
|
|
package service
|
||
|
|
|
||
|
|
import (
|
||
|
|
"runtime"
|
||
|
|
"time"
|
||
|
|
|
||
|
|
"sandc/app/eonline/internal/biz"
|
||
|
|
|
||
|
|
"github.com/go-kratos/kratos/v2/log"
|
||
|
|
)
|
||
|
|
|
||
|
|
var (
|
||
|
|
timeoutTimerPer10Second int64
|
||
|
|
timer10second *time.Timer
|
||
|
|
timer10mintus *time.Timer
|
||
|
|
)
|
||
|
|
|
||
|
|
func InitTimer() {
|
||
|
|
onTimerPer10Second()
|
||
|
|
onTimerPer10Minute()
|
||
|
|
}
|
||
|
|
|
||
|
|
func onTimerPer10Second() {
|
||
|
|
const duration = 10 * time.Second
|
||
|
|
timer10second = time.AfterFunc(duration, func() {
|
||
|
|
defer func() {
|
||
|
|
if r := recover(); r != nil {
|
||
|
|
buf := make([]byte, 4096)
|
||
|
|
l := runtime.Stack(buf, false)
|
||
|
|
log.Infof("onTimerPer10Second error: %v: %s", r, buf[:l])
|
||
|
|
}
|
||
|
|
}()
|
||
|
|
defer onTimerPer10Second()
|
||
|
|
|
||
|
|
begin := time.Now().UnixNano()
|
||
|
|
|
||
|
|
onBreatheFenHong()
|
||
|
|
|
||
|
|
end := time.Now().UnixNano()
|
||
|
|
delta := end - begin
|
||
|
|
if delta > timeoutTimerPer10Second {
|
||
|
|
log.Infof("onTimerPer10Second: begin[%dns] end[%dns], spend[%dms %dns] > [%dns]", begin, end, delta/biz.NS2MS, delta%biz.NS2MS, timeoutTimerPer10Second)
|
||
|
|
}
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
func onTimerPer10Minute() {
|
||
|
|
const duration = 10*time.Minute + 1*time.Second
|
||
|
|
timer10mintus = time.AfterFunc(duration, func() {
|
||
|
|
defer func() {
|
||
|
|
if r := recover(); r != nil {
|
||
|
|
buf := make([]byte, 4096)
|
||
|
|
l := runtime.Stack(buf, false)
|
||
|
|
log.Infof("onTimerPer10Minute error: %v: %s", r, buf[:l])
|
||
|
|
}
|
||
|
|
}()
|
||
|
|
defer onTimerPer10Minute()
|
||
|
|
|
||
|
|
begin := time.Now().UnixNano()
|
||
|
|
|
||
|
|
biz.SaveSvrDataOnTimer()
|
||
|
|
|
||
|
|
end := time.Now().UnixNano()
|
||
|
|
delta := end - begin
|
||
|
|
log.Infof("onTimerPer10Minute: begin[%dns] end[%dns], spend[%dms %dns]", begin, end, delta/biz.NS2MS, delta%biz.NS2MS)
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
func OnDestroyTimer() {
|
||
|
|
timer10second.Stop()
|
||
|
|
timer10mintus.Stop()
|
||
|
|
}
|