|
|
|
@ -14,19 +14,67 @@ import (
|
|
|
|
|
|
|
|
|
|
const cronTaskOperationID = "cronTaskOperationID-"
|
|
|
|
|
|
|
|
|
|
func StartCronTask() {
|
|
|
|
|
func StartCronTask(userID, workingGroupID string) {
|
|
|
|
|
log.NewPrivateLog("cron")
|
|
|
|
|
log.NewInfo(utils.OperationIDGenerator(), "start cron task", "cron config", config.Config.Mongo.ChatRecordsClearTime)
|
|
|
|
|
c := cron.New()
|
|
|
|
|
fmt.Println("cron config", config.Config.Mongo.ChatRecordsClearTime)
|
|
|
|
|
_, err := c.AddFunc(config.Config.Mongo.ChatRecordsClearTime, func() {
|
|
|
|
|
// user msg clear
|
|
|
|
|
if userID != "" {
|
|
|
|
|
operationID := getCronTaskOperationID()
|
|
|
|
|
StartClearMsg(operationID, []string{userID})
|
|
|
|
|
}
|
|
|
|
|
if workingGroupID != "" {
|
|
|
|
|
operationID := getCronTaskOperationID()
|
|
|
|
|
StartClearWorkingGroupMsg(operationID, []string{workingGroupID})
|
|
|
|
|
}
|
|
|
|
|
if userID != "" || workingGroupID != "" {
|
|
|
|
|
fmt.Println("clear msg finished")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
clearFunc := func() {
|
|
|
|
|
ClearAll()
|
|
|
|
|
}
|
|
|
|
|
c := cron.New()
|
|
|
|
|
_, err := c.AddFunc(config.Config.Mongo.ChatRecordsClearTime, clearFunc)
|
|
|
|
|
if err != nil {
|
|
|
|
|
fmt.Println("start cron failed", err.Error(), config.Config.Mongo.ChatRecordsClearTime)
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
c.Start()
|
|
|
|
|
fmt.Println("start cron task success")
|
|
|
|
|
for {
|
|
|
|
|
time.Sleep(10 * time.Second)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func getCronTaskOperationID() string {
|
|
|
|
|
return cronTaskOperationID + utils.OperationIDGenerator()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func ClearAll() {
|
|
|
|
|
operationID := getCronTaskOperationID()
|
|
|
|
|
log.NewInfo(operationID, "====================== start del cron task ======================")
|
|
|
|
|
//var userIDList []string
|
|
|
|
|
var err error
|
|
|
|
|
userIDList, err := im_mysql_model.SelectAllUserID()
|
|
|
|
|
if err == nil {
|
|
|
|
|
StartClearMsg(operationID, userIDList)
|
|
|
|
|
} else {
|
|
|
|
|
log.NewError(operationID, utils.GetSelfFuncName(), err.Error())
|
|
|
|
|
}
|
|
|
|
|
//return
|
|
|
|
|
// working group msg clear
|
|
|
|
|
workingGroupIDList, err := im_mysql_model.GetGroupIDListByGroupType(constant.WorkingGroup)
|
|
|
|
|
if err == nil {
|
|
|
|
|
StartClearWorkingGroupMsg(operationID, workingGroupIDList)
|
|
|
|
|
} else {
|
|
|
|
|
log.NewError(operationID, utils.GetSelfFuncName(), err.Error())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log.NewInfo(operationID, "====================== start del cron finished ======================")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func StartClearMsg(operationID string, userIDList []string) {
|
|
|
|
|
log.NewDebug(operationID, utils.GetSelfFuncName(), "userIDList: ", userIDList)
|
|
|
|
|
userIDList = []string{"4158779020"}
|
|
|
|
|
for _, userID := range userIDList {
|
|
|
|
|
if err := DeleteMongoMsgAndResetRedisSeq(operationID, userID); err != nil {
|
|
|
|
|
log.NewError(operationID, utils.GetSelfFuncName(), err.Error(), userID)
|
|
|
|
@ -35,21 +83,17 @@ func StartCronTask() {
|
|
|
|
|
log.NewError(operationID, utils.GetSelfFuncName(), userID, err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
log.NewError(operationID, utils.GetSelfFuncName(), err.Error())
|
|
|
|
|
}
|
|
|
|
|
//return
|
|
|
|
|
// working group msg clear
|
|
|
|
|
workingGroupIDList, err := im_mysql_model.GetGroupIDListByGroupType(constant.WorkingGroup)
|
|
|
|
|
if err == nil {
|
|
|
|
|
|
|
|
|
|
func StartClearWorkingGroupMsg(operationID string, workingGroupIDList []string) {
|
|
|
|
|
log.NewDebug(operationID, utils.GetSelfFuncName(), "workingGroupIDList: ", workingGroupIDList)
|
|
|
|
|
for _, groupID := range workingGroupIDList {
|
|
|
|
|
userIDList, err = rocksCache.GetGroupMemberIDListFromCache(groupID)
|
|
|
|
|
userIDList, err := rocksCache.GetGroupMemberIDListFromCache(groupID)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.NewError(operationID, utils.GetSelfFuncName(), err.Error(), groupID)
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
log.NewDebug(operationID, utils.GetSelfFuncName(), "groupID:", groupID, "userIDList:", userIDList)
|
|
|
|
|
log.NewDebug(operationID, utils.GetSelfFuncName(), "groupID:", groupID, "workingGroupIDList:", userIDList)
|
|
|
|
|
if err := ResetUserGroupMinSeq(operationID, groupID, userIDList); err != nil {
|
|
|
|
|
log.NewError(operationID, utils.GetSelfFuncName(), err.Error(), groupID, userIDList)
|
|
|
|
|
}
|
|
|
|
@ -57,24 +101,4 @@ func StartCronTask() {
|
|
|
|
|
log.NewError(operationID, utils.GetSelfFuncName(), groupID, err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
log.NewError(operationID, utils.GetSelfFuncName(), err.Error())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log.NewInfo(operationID, "====================== start del cron finished ======================")
|
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
fmt.Println("start cron failed", err.Error(), config.Config.Mongo.ChatRecordsClearTime)
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
c.Start()
|
|
|
|
|
fmt.Println("start cron task success")
|
|
|
|
|
for {
|
|
|
|
|
time.Sleep(10 * time.Second)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func getCronTaskOperationID() string {
|
|
|
|
|
return cronTaskOperationID + utils.OperationIDGenerator()
|
|
|
|
|
}
|
|
|
|
|