This commit is contained in:
aozhiwei 2020-09-08 16:04:50 +08:00
parent 38e094fec2
commit cc1a26b982
3 changed files with 37 additions and 28 deletions

21
app.go
View File

@ -25,7 +25,20 @@ type App_ struct {
func (this *App_) Init() { func (this *App_) Init() {
_Timer = &q5.Timer{} _Timer = &q5.Timer{}
_Timer.Init( _Timer.Init(
q5.GetTickCount, func (context interface{}) int64 {
return q5.GetTickCount()
},
func (context interface{}, fixedTimierExecuteTimes int32, milliSeconds int32, tick int64) int64 {
nowTime := time.Now().Unix()
todayPassedSeconds := nowTime - q5.GetDaySeconds(nowTime)
expires := (tick - todayPassedSeconds * 1000) + int64(milliSeconds)
if fixedTimierExecuteTimes > 0 {
if expires <= tick {
expires += 1000 * 3600 * 24
}
}
return expires
},
nil, nil,
1000 * 60, 1000 * 60,
5000) 5000)
@ -82,9 +95,7 @@ func (this *App_) AddIMMsg(msgId int16, params *q5.XParams) {
p.msgId = msgId p.msgId = msgId
p.params = params p.params = params
{
this.imMsgMutex.Lock() this.imMsgMutex.Lock()
defer this.imMsgMutex.Unlock()
if this.imBotNode != nil { if this.imBotNode != nil {
this.imBotNode.next = p this.imBotNode.next = p
this.imBotNode = p this.imBotNode = p
@ -92,7 +103,8 @@ func (this *App_) AddIMMsg(msgId int16, params *q5.XParams) {
this.imTopNode = p this.imTopNode = p
this.imBotNode = p this.imBotNode = p
} }
} this.imMsgMutex.Unlock()
this.loopCond.Broadcast() this.loopCond.Broadcast()
} }
@ -116,3 +128,4 @@ func (this *App_) schedule() {
this.loopCond.Wait() this.loopCond.Wait()
this.loopCond.L.Unlock() this.loopCond.L.Unlock()
} }

View File

@ -114,25 +114,23 @@ func (this *SysLog_) goSaveToFile() {
select { select {
case <-this.chGoSaveExit: case <-this.chGoSaveExit:
return return
case <-time.After(time.Millisecond * 1000 * 10): case <-time.After(time.Millisecond * 10):
} }
{
this.msgMutex.Lock() this.msgMutex.Lock()
defer this.msgMutex.Unlock()
workNode = this.topNode workNode = this.topNode
this.topNode = nil this.topNode = nil
this.botNode = nil this.botNode = nil
} this.msgMutex.Unlock()
if workNode != nil { if workNode != nil {
logDir := fmt.Sprintf(SYS_LOG_ROOT, App.GetPkgName()) logDir := fmt.Sprintf(SYS_LOG_ROOT, App.GetPkgName())
fileName := fmt.Sprintf(TGLOG_FILENAME, os.Getpid(), time.Now().Format("20060102")) fileName := fmt.Sprintf(TGLOG_FILENAME, os.Getpid(), time.Now().Format("20060102"))
q5.ForceCreateDir(logDir) q5.ForceCreateDir(logDir)
if f, err := os.OpenFile(logDir + fileName, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0666); err == nil { if f, err := os.OpenFile(logDir + fileName, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0666); err == nil {
defer f.Close()
for workNode != nil { for workNode != nil {
f.Write([]byte(workNode.logMsg)) f.Write([]byte(workNode.logMsg))
workNode = workNode.next workNode = workNode.next
} }
f.Close()
} else { } else {
fmt.Println(err) fmt.Println(err)
} }

View File

@ -80,19 +80,17 @@ func (this *TGLog_) goSaveToFile() {
return return
case <-time.After(time.Millisecond * 1000 * 10): case <-time.After(time.Millisecond * 1000 * 10):
} }
{
this.msgMutex.Lock() this.msgMutex.Lock()
defer this.msgMutex.Unlock()
workNode = this.topNode workNode = this.topNode
this.topNode = nil this.topNode = nil
this.botNode = nil this.botNode = nil
} this.msgMutex.Unlock()
if workNode != nil { if workNode != nil {
for workNode != nil { for workNode != nil {
f := this.getLogFile(workNode.gameId) f := this.getLogFile(workNode.gameId)
if f != nil { if f != nil {
defer f.Close()
f.Write([]byte(workNode.jsonStr + "\n")) f.Write([]byte(workNode.jsonStr + "\n"))
f.Close()
} }
workNode = workNode.next workNode = workNode.next
} }