1
This commit is contained in:
parent
fcc9cbc260
commit
5f89f20777
@ -5,6 +5,7 @@ import (
|
||||
"main/constant"
|
||||
"mt"
|
||||
"main/middleware"
|
||||
. "main/global"
|
||||
)
|
||||
|
||||
type app struct {
|
||||
@ -49,8 +50,16 @@ func (this *app) registerDataSources() {
|
||||
mt.Table.MailDb.GetById(0).GetPasswd(),
|
||||
mt.Table.MailDb.GetById(0).GetDatabase(),
|
||||
3)
|
||||
f5.GetJsStyleDb().RegisterDataSource(
|
||||
constant.MAIL_DB,
|
||||
mt.Table.MailDb.GetById(0).GetHost(),
|
||||
mt.Table.MailDb.GetById(0).GetPort(),
|
||||
mt.Table.MailDb.GetById(0).GetUser(),
|
||||
mt.Table.MailDb.GetById(0).GetPasswd(),
|
||||
mt.Table.MailDb.GetById(0).GetDatabase(),
|
||||
1)
|
||||
}
|
||||
|
||||
func (this *app) HasTask() bool {
|
||||
return false
|
||||
return GetMailMgr().HasTask()
|
||||
}
|
||||
|
@ -58,4 +58,5 @@ type MailMgr interface{
|
||||
CaGetUnreadMailCnt(c *gin.Context)
|
||||
CaGetAttachment(c *gin.Context)
|
||||
CaDeleteMails(c *gin.Context)
|
||||
HasTask() bool
|
||||
}
|
||||
|
@ -10,6 +10,13 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type dbEvent struct {
|
||||
idx int64
|
||||
eventName string
|
||||
param1 string
|
||||
entry q5.ListHead
|
||||
}
|
||||
|
||||
type userGroup struct {
|
||||
groupId int64
|
||||
userHash sync.Map
|
||||
@ -23,9 +30,13 @@ type mailMgr struct {
|
||||
groupHash sync.Map //int64 => *userGroup
|
||||
lastSyncEventIdx int64
|
||||
pullingEvent bool
|
||||
procingEvent bool
|
||||
eventQueue q5.Queue
|
||||
timerWp *f5.TimerWp
|
||||
}
|
||||
|
||||
func (this *mailMgr) Init() {
|
||||
this.eventQueue.Init()
|
||||
this.syncEvent()
|
||||
this.loadMails()
|
||||
this.loadGroups()
|
||||
@ -35,9 +46,18 @@ func (this *mailMgr) Init() {
|
||||
f5.GetApp().RegisterCaHandle("Mail", "getUnreadMailCnt", this.CaGetUnreadMailCnt)
|
||||
f5.GetApp().RegisterCaHandle("Mail", "getAttachment", this.CaGetAttachment)
|
||||
f5.GetApp().RegisterCaHandle("Mail", "deleteMails", this.CaDeleteMails)
|
||||
this.timerWp = f5.GetTimer().SetIntervalWp(
|
||||
300,
|
||||
func (e int32, args* q5.Args) {
|
||||
if e == q5.TIMER_EXEC_EVENT {
|
||||
this.updateDbEvent()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (this *mailMgr) UnInit() {
|
||||
f5.GetTimer().Delete(this.timerWp)
|
||||
this.timerWp = nil
|
||||
}
|
||||
|
||||
func (this *mailMgr) loadMails() {
|
||||
@ -306,21 +326,84 @@ func (this *mailMgr) syncEvent() {
|
||||
})
|
||||
}
|
||||
|
||||
func (this *mailMgr) addDbEvent(e *dbEvent) {
|
||||
this.eventQueue.Push(&e.entry)
|
||||
}
|
||||
|
||||
func (this *mailMgr) updateDbEvent() {
|
||||
if this.eventQueue.IsEmpty() {
|
||||
return
|
||||
}
|
||||
if this.procingEvent {
|
||||
return
|
||||
}
|
||||
this.eventQueue.Fetch()
|
||||
for !this.eventQueue.WorkList.Empty() {
|
||||
e := this.eventQueue.WorkList.FirstEntry().(*dbEvent)
|
||||
if e.eventName == constant.EVENT_MAIL_UPDATE {
|
||||
this.procMailUpdate(e)
|
||||
break
|
||||
} else if e.eventName == constant.EVENT_UPSER_GROUP_UPDATE {
|
||||
this.procGroupUpdate(e)
|
||||
break
|
||||
} else {
|
||||
e.entry.DelInit()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (this *mailMgr) pullEvent() {
|
||||
if this.pullingEvent {
|
||||
return
|
||||
}
|
||||
this.pullingEvent = true
|
||||
go f5.GetJsStyleDb().SelectCustomQuery(
|
||||
f5.GetJsStyleDb().SelectCustomQuery(
|
||||
constant.MAIL_DB,
|
||||
fmt.Sprintf("SELECT * FROM t_event WHERE idx > %d;", this.lastSyncEventIdx),
|
||||
func(err error, ds *f5.DataSet) {
|
||||
this.pullingEvent = false
|
||||
if err != nil {
|
||||
this.pullingEvent = false
|
||||
return
|
||||
}
|
||||
for ds.Next() {
|
||||
e := new(dbEvent)
|
||||
e.idx = q5.ToInt64(ds.GetByName("idx"))
|
||||
e.eventName = ds.GetByName("event_name")
|
||||
e.param1 = ds.GetByName("param1")
|
||||
e.entry.Init(e)
|
||||
_mailMgr.addDbEvent(e)
|
||||
this.lastSyncEventIdx = q5.ToInt64(ds.GetByName("idx"))
|
||||
}
|
||||
this.pullingEvent = false
|
||||
})
|
||||
}
|
||||
|
||||
func (this* mailMgr) HasTask() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (this* mailMgr) procMailUpdate(e *dbEvent) {
|
||||
this.procingEvent = true
|
||||
f5.GetJsStyleDb().OrmSelectOne(
|
||||
constant.MAIL_DB,
|
||||
"t_mail",
|
||||
[][]string{
|
||||
{"mail_id", e.param1},
|
||||
},
|
||||
func (err error, ds *f5.DataSet) {
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
func (this* mailMgr) procGroupUpdate(e *dbEvent) {
|
||||
this.procingEvent = true
|
||||
f5.GetJsStyleDb().OrmSelectOne(
|
||||
constant.MAIL_DB,
|
||||
"t_group",
|
||||
[][]string{
|
||||
{"group_id", e.param1},
|
||||
},
|
||||
func (err error, ds *f5.DataSet) {
|
||||
|
||||
})
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user