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])
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 {