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 ( import (
"crypto/md5" "crypto/md5"
@@ -10,6 +10,7 @@ import (
"path/filepath" "path/filepath"
"strconv" "strconv"
"strings" "strings"
"time"
"quyun/app/service" "quyun/app/service"
@@ -50,16 +51,21 @@ type compressedDB struct {
} }
func Serve(cmd *cobra.Command, args []string) error { func Serve(cmd *cobra.Command, args []string) error {
log.SetFormatter(&log.JSONFormatter{}) // log.SetFormatter(&log.JSONFormatter{})
if len(args) == 0 { if len(args) == 0 {
return errors.New("usage: compress <path>") return errors.New("usage: compress path")
} }
if err := commandCompress(args[0]); err != nil { ticker := time.NewTicker(5 * time.Minute)
return err 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 return nil
} }

View File

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

View File

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