This commit is contained in:
aozhiwei 2023-08-12 19:05:12 +08:00
parent b1b47302a3
commit 1e0148bd50
4 changed files with 32 additions and 43 deletions

40
app.go
View File

@ -16,7 +16,7 @@ type App_ struct {
pkgName string
flags map[int32]int32
servicing bool
contextHash map[int32]q5.XParams
contextHash map[int32]q5.Args
loopCond *sync.Cond
imTopNode *IMMsgNode
imBotNode *IMMsgNode
@ -26,7 +26,7 @@ type App_ struct {
chGoLoopWait chan int64
nowTime time.Time
nowUnixNano int64
imMsgHandlers [1024]func(int16,*q5.XParams)
imMsgHandlers [1024]func(int16, q5.Args)
maxRunDelay int64
maxScheduleTime int64
updateFunc func ()
@ -36,22 +36,11 @@ func (this *App_) Init(updateFunc func ()) {
this.updateFunc = updateFunc
this.nowTime = time.Now()
atomic.StoreInt64(&this.nowUnixNano, this.nowTime.UnixNano())
_Timer = &q5.Timer{}
_Timer = &q5.XTimer{}
_Timer.Init(
func (context interface{}) int64 {
return q5.GetTickCount()
},
func (context interface{}, isFirstAdd bool, milliSeconds int32, tick int64) int64 {
nowTime := time.Now().Unix()
todayPassedSeconds := nowTime - q5.GetDaySeconds(nowTime)
expires := (tick - todayPassedSeconds * 1000) + int64(milliSeconds)
if isFirstAdd {
if expires <= tick {
expires += 1000 * 3600 * 24
}
}
return expires
},
nil,
1000 * 60,
5000)
@ -123,7 +112,7 @@ func (this *App_) HasFlag(flag int32) bool {
return ok
}
func (this *App_) AddIMMsg(msgId int16, params *q5.XParams) {
func (this *App_) AddIMMsg(msgId int16, params q5.Args) {
p := new(IMMsgNode)
p.msgId = msgId
p.params = params
@ -141,7 +130,7 @@ func (this *App_) AddIMMsg(msgId int16, params *q5.XParams) {
this.loopCond.Broadcast()
}
func (this *App_) RegisterIMMsgHandle(msgId int16, handle func(int16,*q5.XParams)) {
func (this *App_) RegisterIMMsgHandle(msgId int16, handle func(int16,q5.Args)) {
this.imMsgHandlers[msgId] = handle
}
@ -208,15 +197,14 @@ func (this *App_) dispatchIMMsg() {
}
func (this *App_) installTimer() {
Timer().AddRepeatTimer(1000 * 60,
func (params* q5.XParams) {
},
func (params* q5.XParams) {
SysLog().Info("max_run_delay:%d max_schedule_time:%d",
App.maxRunDelay,
App.maxScheduleTime)
App.maxRunDelay = 0
App.maxScheduleTime = 0
Timer().SetInterval(1000 * 60,
func (ev int32, params *q5.Args) {
if ev == q5.TIMER_EXEC_EVENT {
SysLog().Info("max_run_delay:%d max_schedule_time:%d",
App.maxRunDelay,
App.maxScheduleTime)
App.maxRunDelay = 0
App.maxScheduleTime = 0
}
})
}

View File

@ -3,11 +3,11 @@ package f5
import "q5"
var App *App_
var _Timer *q5.Timer
var _Timer *q5.XTimer
var _SysLog *SysLog_
var _TgLog *TGLog_
func Timer() *q5.Timer {
func Timer() *q5.XTimer {
return _Timer
}

View File

@ -42,21 +42,22 @@ func (this *HttpServer) Init(serviceName string, logOutputTime int32) *HttpServe
})
SysLog().Info("HttpServer.Init")
if logOutputTime > 0 {
Timer().AddRepeatTimer(
Timer().SetInterval(
logOutputTime,
func (params* q5.XParams) {
params.Sender.SetString(serviceName)
},
func (params* q5.XParams) {
SysLog().Info("%s maxHandleTime:%d totalRequestTimes:%d okTimes:%d pageNotFoundTimes:%d",
params.Sender.GetString(),
this.maxHandleTime,
this.totalRequestTimes,
this.okTimes,
this.pageNotFoundTimes)
this.maxHandleTime = 0
this.okTimes = 0
this.pageNotFoundTimes = 0
func (ev int32, params *q5.Args) {
if ev == q5.TIMER_EXEC_EVENT {
/*
SysLog().Info("%s maxHandleTime:%d totalRequestTimes:%d okTimes:%d pageNotFoundTimes:%d",
params.Sender.GetString(),
this.maxHandleTime,
this.totalRequestTimes,
this.okTimes,
this.pageNotFoundTimes)
this.maxHandleTime = 0
this.okTimes = 0
this.pageNotFoundTimes = 0
*/
}
})
}
return this

View File

@ -17,7 +17,7 @@ type MsgNode struct {
type IMMsgNode struct {
msgId int16
params *q5.XParams
params q5.Args
next *IMMsgNode
}