feat: update compress ticker

This commit is contained in:
yanghao05
2025-03-29 17:55:44 +08:00
parent 754f938e76
commit a48a3b6a1f
3 changed files with 16 additions and 8 deletions

View File

@@ -1,4 +1,4 @@
package queue
package commands
import (
"crypto/md5"
@@ -10,6 +10,7 @@ import (
"path/filepath"
"strconv"
"strings"
"time"
"quyun/app/service"
@@ -50,16 +51,21 @@ type compressedDB struct {
}
func Serve(cmd *cobra.Command, args []string) error {
log.SetFormatter(&log.JSONFormatter{})
// log.SetFormatter(&log.JSONFormatter{})
if len(args) == 0 {
return errors.New("usage: compress <path>")
return errors.New("usage: compress path")
}
if err := commandCompress(args[0]); err != nil {
return err
}
ticker := time.NewTicker(5 * time.Minute)
for range ticker.C {
log.Infof("compressing %s", args[0])
if err := commandCompress(args[0]); err != nil {
log.WithError(err).Errorf("compressing %s failed", args[0])
continue
}
log.Infof("compressing %s done", args[0])
}
return nil
}

View File

@@ -1,4 +1,4 @@
package queue
package commands
import (
"os"

View File

@@ -1,6 +1,7 @@
package main
import (
"quyun/app/service/commands"
"quyun/app/service/http"
"quyun/app/service/migrate"
@@ -27,6 +28,7 @@ func main() {
atom.Name("quyun"),
http.Command(),
migrate.Command(),
commands.Command(),
}
if err := atom.Serve(opts...); err != nil {