1
This commit is contained in:
parent
008dfa0ace
commit
a5088a47cc
@ -158,7 +158,8 @@ CREATE TABLE `t_param` (
|
||||
`param_val1` varchar(255) CHARACTER SET utf8 NOT NULL DEFAULT '' COMMENT '参数1',
|
||||
`createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间',
|
||||
`modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间',
|
||||
PRIMARY KEY (`idx`)
|
||||
UNIQUE KEY `idx` (`idx`),
|
||||
PRIMARY KEY (`param_name`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=10000 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
"f5"
|
||||
"fmt"
|
||||
"main/constant"
|
||||
"main/model/system"
|
||||
"main/task"
|
||||
"math/rand"
|
||||
"mt"
|
||||
"sync"
|
||||
@ -40,10 +40,12 @@ func (this *app) Init() {
|
||||
this.registerDataSources()
|
||||
this.sessionHash = make(map[string]string)
|
||||
this.accountIdHash = make(map[string]string)
|
||||
task.TaskMgr.Init()
|
||||
this.initCb()
|
||||
}
|
||||
|
||||
func (this *app) UnInit() {
|
||||
task.TaskMgr.UnInit()
|
||||
this.unInitCb()
|
||||
}
|
||||
|
||||
@ -100,10 +102,6 @@ func (this *app) registerDataSources() {
|
||||
mt.Table.MailDb.GetById(0).GetDatabase(),
|
||||
1,
|
||||
)
|
||||
|
||||
u := system.SysUser{}
|
||||
f5.GetApp().GetOrmDb(constant.ADMIN_DB).First(&u)
|
||||
f5.GetSysLog().Info("%s %s", u)
|
||||
}
|
||||
|
||||
func (this *app) AddSession(accountId string) string {
|
||||
|
@ -36,3 +36,7 @@ const (
|
||||
EVENT_MAIL_UPDATE = "mail.update"
|
||||
EVENT_UPSER_GROUP_UPDATE = "user_group.update"
|
||||
)
|
||||
|
||||
const (
|
||||
PARAM_NAME_LAST_SYNC_SYS_MAIL_IDX = "last_sync_sys_mail_idx"
|
||||
)
|
||||
|
@ -1,14 +1,59 @@
|
||||
package task
|
||||
|
||||
type taskMgr struct {
|
||||
import (
|
||||
"q5"
|
||||
"f5"
|
||||
"fmt"
|
||||
"sync"
|
||||
"time"
|
||||
"main/constant"
|
||||
)
|
||||
|
||||
type taskMgr struct {
|
||||
lastSyncSysMailIdx int64
|
||||
syncSysMailCond *sync.Cond
|
||||
}
|
||||
|
||||
var TaskMgr = new(taskMgr)
|
||||
|
||||
func (this *taskMgr) Init() {
|
||||
|
||||
this.syncSysMailCond = sync.NewCond(new(sync.Mutex))
|
||||
f5.GetGoStyleDb().OrmSelectOne(
|
||||
constant.MAIL_DB,
|
||||
"t_param",
|
||||
[][]string{
|
||||
{"param_name", constant.PARAM_NAME_LAST_SYNC_SYS_MAIL_IDX},
|
||||
},
|
||||
func (err error, ds *f5.DataSet) {
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("taskMgr init err:%s", err))
|
||||
return
|
||||
}
|
||||
if ds.Next() {
|
||||
this.lastSyncSysMailIdx = q5.ToInt64(ds.GetByName("param_val1"))
|
||||
}
|
||||
go this.syncSysMail()
|
||||
})
|
||||
}
|
||||
|
||||
func (this *taskMgr) UnInit() {
|
||||
|
||||
}
|
||||
|
||||
func (this *taskMgr) syncSysMail() {
|
||||
go func () {
|
||||
var waitMs int64 = 1000 * 2
|
||||
for {
|
||||
select {
|
||||
case <-time.After(time.Millisecond * time.Duration(waitMs)):
|
||||
waitMs = 1000 * 2
|
||||
this.syncSysMailCond.Broadcast()
|
||||
}
|
||||
}
|
||||
}()
|
||||
for true {
|
||||
this.syncSysMailCond.L.Lock()
|
||||
this.syncSysMailCond.Wait()
|
||||
this.syncSysMailCond.L.Unlock()
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user