mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-10 20:15:59 +08:00
v3 - main to cut out
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
package timed_task
|
||||
|
||||
type TimeTask struct {
|
||||
delMgoChatChan chan bool
|
||||
}
|
||||
|
||||
var timeTask TimeTask
|
||||
|
||||
func GetInstance() *TimeTask {
|
||||
if timeTask.delMgoChatChan == nil {
|
||||
timeTask.delMgoChatChan = make(chan bool)
|
||||
go func() {
|
||||
timeTask.delMgoChatChan <- true
|
||||
}()
|
||||
}
|
||||
return &timeTask
|
||||
}
|
||||
|
||||
func (t *TimeTask) Run() {
|
||||
for {
|
||||
select {
|
||||
case <-t.delMgoChatChan:
|
||||
t.timedDeleteUserChat()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package timed_task
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/db"
|
||||
"time"
|
||||
)
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
go func() {
|
||||
t.delMgoChatChan <- true
|
||||
}()
|
||||
}
|
||||
Reference in New Issue
Block a user