From 4cdda96d6edf5c8c65db089f060c39d878ba66bf Mon Sep 17 00:00:00 2001 From: yanghao05 Date: Sat, 29 Mar 2025 18:44:34 +0800 Subject: [PATCH] feat: add compress command --- backend/app/service/commands/compress.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/backend/app/service/commands/compress.go b/backend/app/service/commands/compress.go index d6d5881..3d151a2 100644 --- a/backend/app/service/commands/compress.go +++ b/backend/app/service/commands/compress.go @@ -57,22 +57,23 @@ func Serve(cmd *cobra.Command, args []string) error { } log.Infof("start compressing %s", args[0]) - if err := commandCompress(args[0]); err != nil { - log.WithError(err).Errorf("compressing %s failed", args[0]) - return err - } - - ticker := time.NewTicker(5 * time.Minute) - for range ticker.C { + failTimes := 0 + for { log.Infof("start compressing %s", args[0]) if err := commandCompress(args[0]); err != nil { log.WithError(err).Errorf("compressing %s failed", args[0]) + failTimes++ + + if failTimes >= 3 { + return errors.New("failed to compress after 3 attempts") + } continue } log.Infof("compressing %s done", args[0]) + + time.Sleep(5 * time.Minute) } - return nil } func commandCompress(dir string) error {