feat: add compress command

This commit is contained in:
yanghao05
2025-03-29 18:44:34 +08:00
parent 5770f3a425
commit 4cdda96d6e

View File

@@ -57,22 +57,23 @@ func Serve(cmd *cobra.Command, args []string) error {
} }
log.Infof("start compressing %s", args[0]) log.Infof("start compressing %s", args[0])
if err := commandCompress(args[0]); err != nil { failTimes := 0
log.WithError(err).Errorf("compressing %s failed", args[0]) for {
return err
}
ticker := time.NewTicker(5 * time.Minute)
for range ticker.C {
log.Infof("start compressing %s", args[0]) log.Infof("start compressing %s", args[0])
if err := commandCompress(args[0]); err != nil { if err := commandCompress(args[0]); err != nil {
log.WithError(err).Errorf("compressing %s failed", args[0]) log.WithError(err).Errorf("compressing %s failed", args[0])
failTimes++
if failTimes >= 3 {
return errors.New("failed to compress after 3 attempts")
}
continue continue
} }
log.Infof("compressing %s done", args[0]) log.Infof("compressing %s done", args[0])
time.Sleep(5 * time.Minute)
} }
return nil
} }
func commandCompress(dir string) error { func commandCompress(dir string) error {