From a5088a47cce1d4ae4604a145803096190e04cbdd Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Wed, 5 Jun 2024 12:05:24 +0800 Subject: [PATCH] 1 --- database/maildb.sql | 3 +- server/adminserver/app/app.go | 8 ++-- server/adminserver/constant/constant.go | 4 ++ server/adminserver/task/taskmgr.go | 49 ++++++++++++++++++++++++- 4 files changed, 56 insertions(+), 8 deletions(-) diff --git a/database/maildb.sql b/database/maildb.sql index 560f4fd1..7500aab8 100644 --- a/database/maildb.sql +++ b/database/maildb.sql @@ -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 */; diff --git a/server/adminserver/app/app.go b/server/adminserver/app/app.go index e0a7c7d9..9a6b962e 100644 --- a/server/adminserver/app/app.go +++ b/server/adminserver/app/app.go @@ -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 { diff --git a/server/adminserver/constant/constant.go b/server/adminserver/constant/constant.go index 4b80c3ef..513e6efc 100644 --- a/server/adminserver/constant/constant.go +++ b/server/adminserver/constant/constant.go @@ -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" +) diff --git a/server/adminserver/task/taskmgr.go b/server/adminserver/task/taskmgr.go index 0af52d35..681fd875 100644 --- a/server/adminserver/task/taskmgr.go +++ b/server/adminserver/task/taskmgr.go @@ -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() + } +}