Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: delay deleteObject func. #2566

Merged
merged 27 commits into from
Aug 29, 2024
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
6fa9d93
refactor: refactor workflows contents.
mo3et Aug 12, 2024
c8dec9f
add tool workflows.
mo3et Aug 12, 2024
5511ad3
update field.
mo3et Aug 12, 2024
c50bce3
fix: remove chat error.
mo3et Aug 12, 2024
5471d1c
Fix err.
mo3et Aug 12, 2024
3101f14
fix error.
mo3et Aug 12, 2024
72aca1e
remove cn comment.
mo3et Aug 12, 2024
002cdde
update workflows files.
mo3et Aug 12, 2024
a281442
update infra config.
mo3et Aug 12, 2024
fa54e57
move workflows.
mo3et Aug 12, 2024
f100cab
feat: update bot.
mo3et Aug 12, 2024
e5435cd
Merge branch 'openimsdk:main' into main
mo3et Aug 12, 2024
4ef9200
fix: solve uncorrect outdated msg get.
mo3et Aug 13, 2024
9b46304
Merge branch 'main' of github.com:mo3et/open-im-server
mo3et Aug 13, 2024
bc47a6a
update get docIDs logic.
mo3et Aug 13, 2024
7c482c9
update
mo3et Aug 13, 2024
d467381
update skip logic.
mo3et Aug 13, 2024
a2bbb6a
fix
mo3et Aug 13, 2024
850b7b2
update.
mo3et Aug 13, 2024
e8789bd
Merge branch 'main' of github.com:openimsdk/open-im-server
mo3et Aug 14, 2024
4539151
Merge branch 'main' of github.com:openimsdk/open-im-server
mo3et Aug 19, 2024
8c1c1b6
Merge branch 'main' of github.com:openimsdk/open-im-server
mo3et Aug 20, 2024
d4a4d67
Merge branch 'main' of github.com:openimsdk/open-im-server
mo3et Aug 21, 2024
d63c5b7
Merge branch 'main' of github.com:openimsdk/open-im-server
mo3et Aug 21, 2024
fcb210d
Merge branch 'main' of github.com:openimsdk/open-im-server
mo3et Aug 29, 2024
6bc5264
fix: delay deleteObject func.
mo3et Aug 29, 2024
0e90f78
remove unused content.
mo3et Aug 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 20 additions & 21 deletions internal/tools/cron_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
pbconversation "github.com/openimsdk/protocol/conversation"
"github.com/openimsdk/protocol/msg"

"github.com/openimsdk/protocol/third"
"github.com/openimsdk/tools/mcontext"
"github.com/openimsdk/tools/mw"
"google.golang.org/grpc"
Expand Down Expand Up @@ -59,10 +58,10 @@ func Start(ctx context.Context, config *CronTaskConfig) error {
return err
}

thirdConn, err := client.GetConn(ctx, config.Share.RpcRegisterName.Third)
if err != nil {
return err
}
// thirdConn, err := client.GetConn(ctx, config.Share.RpcRegisterName.Third)
// if err != nil {
// return err
// }

conversationConn, err := client.GetConn(ctx, config.Share.RpcRegisterName.Conversation)
if err != nil {
Expand All @@ -71,7 +70,7 @@ func Start(ctx context.Context, config *CronTaskConfig) error {

msgClient := msg.NewMsgClient(msgConn)
conversationClient := pbconversation.NewConversationClient(conversationConn)
thirdClient := third.NewThirdClient(thirdConn)
// thirdClient := third.NewThirdClient(thirdConn)

crontab := cron.New()

Expand Down Expand Up @@ -115,21 +114,21 @@ func Start(ctx context.Context, config *CronTaskConfig) error {
return errs.Wrap(err)
}

// scheduled delete outdated file Objects and their datas in specific time.
deleteObjectFunc := func() {
now := time.Now()
deleteTime := now.Add(-time.Hour * 24 * time.Duration(config.CronTask.FileExpireTime))
ctx := mcontext.SetOperationID(ctx, fmt.Sprintf("cron_%d_%d", os.Getpid(), deleteTime.UnixMilli()))
log.ZInfo(ctx, "deleteoutDatedData ", "deletetime", deleteTime, "timestamp", deleteTime.UnixMilli())
if _, err := thirdClient.DeleteOutdatedData(ctx, &third.DeleteOutdatedDataReq{ExpireTime: deleteTime.UnixMilli()}); err != nil {
log.ZError(ctx, "cron deleteoutDatedData failed", err, "deleteTime", deleteTime, "cont", time.Since(now))
return
}
log.ZInfo(ctx, "cron deleteoutDatedData success", "deltime", deleteTime, "cont", time.Since(now))
}
if _, err := crontab.AddFunc(config.CronTask.CronExecuteTime, deleteObjectFunc); err != nil {
return errs.Wrap(err)
}
// // scheduled delete outdated file Objects and their datas in specific time.
// deleteObjectFunc := func() {
// now := time.Now()
// deleteTime := now.Add(-time.Hour * 24 * time.Duration(config.CronTask.FileExpireTime))
// ctx := mcontext.SetOperationID(ctx, fmt.Sprintf("cron_%d_%d", os.Getpid(), deleteTime.UnixMilli()))
// log.ZInfo(ctx, "deleteoutDatedData ", "deletetime", deleteTime, "timestamp", deleteTime.UnixMilli())
// if _, err := thirdClient.DeleteOutdatedData(ctx, &third.DeleteOutdatedDataReq{ExpireTime: deleteTime.UnixMilli()}); err != nil {
// log.ZError(ctx, "cron deleteoutDatedData failed", err, "deleteTime", deleteTime, "cont", time.Since(now))
// return
// }
// log.ZInfo(ctx, "cron deleteoutDatedData success", "deltime", deleteTime, "cont", time.Since(now))
// }
// if _, err := crontab.AddFunc(config.CronTask.CronExecuteTime, deleteObjectFunc); err != nil {
// return errs.Wrap(err)
// }

log.ZInfo(ctx, "start cron task", "CronExecuteTime", config.CronTask.CronExecuteTime)
crontab.Start()
Expand Down
Loading