aozhiwei b8ccbdd770 1
2024-11-16 15:05:51 +08:00

54 lines
941 B
Go

package service
import (
"q5"
"sync"
)
type logNode struct {
accountId string
logType string
subLogType string
currTime int64
params map[string]string
entry q5.ListHead
}
type log struct {
logQueue q5.Queue
loopCond *sync.Cond
}
func (this *log) init() {
this.logQueue.Init()
this.loopCond = sync.NewCond(new(sync.Mutex))
go this.saveToDb()
}
func (this *log) unInit() {
}
func (this *log) saveToDb() {
for true {
this.logQueue.Fetch()
if this.logQueue.IsEmpty() {
this.loopCond.L.Lock()
this.loopCond.Wait()
this.loopCond.L.Unlock()
}
}
}
func (this *log) AddAsyncLog(accountId string, logType string, subLogType string, currTime int64,
params map[string]string) {
node := new(logNode)
node.accountId = accountId
node.logType = logType
node.subLogType = subLogType
node.currTime = currTime
node.params = params
node.entry.Init(node)
this.logQueue.Push(&node.entry)
this.loopCond.Broadcast()
}