test cron

This commit is contained in:
wangchuxiao 2022-11-02 11:40:55 +08:00
parent 9182f15ee0
commit d391a4d023
3 changed files with 5 additions and 5 deletions

View File

@ -79,7 +79,7 @@ func deleteMongoMsg(operationID string, ID string, index int64, delMsgIDList *[]
if err != nil || msgs.UID == "" {
if err != nil {
if err == db.ErrMsgListNotExist {
log.NewDebug(operationID, utils.GetSelfFuncName(), ID, index, err.Error())
log.NewDebug(operationID, utils.GetSelfFuncName(), "ID:", ID, "index:", index, err.Error())
} else {
log.NewError(operationID, utils.GetSelfFuncName(), "GetUserMsgListByIndex failed", err.Error(), index, ID)
}

View File

@ -16,9 +16,9 @@ const cronTaskOperationID = "cronTaskOperationID-"
func StartCronTask() {
log.NewPrivateLog("cron")
log.NewInfo(utils.OperationIDGenerator(), "start cron task")
log.NewInfo(utils.OperationIDGenerator(), "start cron task", "cron config", config.Config.Mongo.ChatRecordsClearTime)
c := cron.New()
fmt.Println("config", config.Config.Mongo.ChatRecordsClearTime)
fmt.Println("cron config", config.Config.Mongo.ChatRecordsClearTime)
_, err := c.AddFunc(config.Config.Mongo.ChatRecordsClearTime, func() {
// user msg clear
operationID := getCronTaskOperationID()

View File

@ -12,7 +12,6 @@ import (
"fmt"
"github.com/go-redis/redis/v8"
"github.com/gogo/protobuf/sortkeys"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"math/rand"
@ -268,7 +267,8 @@ func (d *DataBases) GetUserMsgListByIndex(ID string, index int64) (*UserChat, er
regex := fmt.Sprintf("/^%s/", ID)
findOpts := options.Find().SetLimit(1).SetSkip(index).SetSort(bson.M{"uid": 1})
var msgs []UserChat
cursor, err := c.Find(ctx, bson.M{"uid": primitive.Regex{Pattern: regex}}, findOpts)
//primitive.Regex{Pattern: regex}
cursor, err := c.Find(ctx, bson.M{"uid": bson.M{"$regex": regex}}, findOpts)
if err != nil {
return nil, utils.Wrap(err, "")
}