group hash

This commit is contained in:
wangchuxiao
2022-08-08 11:30:10 +08:00
parent 4ba248a101
commit 11f29280b1
16 changed files with 351 additions and 123 deletions
+17 -20
View File
@@ -1,26 +1,23 @@
package timed_task
package timedTask
import (
"Open_IM/pkg/common/db"
"time"
"Open_IM/pkg/common/constant"
"Open_IM/pkg/common/log"
"Open_IM/pkg/utils"
"github.com/robfig/cron/v3"
)
func (t *TimeTask) timedDeleteUserChat() {
now := time.Now()
next := now.Add(time.Hour * 24)
next = time.Date(next.Year(), next.Month(), next.Day(), 0, 0, 0, 0, next.Location())
tm := time.NewTimer(next.Sub(now))
<-tm.C
count, _ := db.DB.MgoUserCount()
for i := 0; i < count; i++ {
time.Sleep(10 * time.Millisecond)
uid, _ := db.DB.MgoSkipUID(i)
db.DB.DelUserChatMongo2(uid)
func main() {
log.NewInfo(utils.OperationIDGenerator(), "start cron task")
c := cron.New()
_, err := c.AddFunc("30 3-6,20-23 * * *", func() {
operationID := utils.OperationIDGenerator()
if err := DeleteMongoMsgAndResetRedisSeq(operationID, "", constant.ReadDiffusion); err != nil {
log.NewError(operationID)
}
})
if err != nil {
panic(err)
}
go func() {
t.delMgoChatChan <- true
}()
c.Start()
}