diff --git a/go.mod b/go.mod index f06e84b..0100dde 100644 --- a/go.mod +++ b/go.mod @@ -6,9 +6,9 @@ require ( github.com/caarlos0/env/v10 v10.0.0 github.com/gin-gonic/gin v1.9.1 github.com/golang-jwt/jwt/v5 v5.2.1 + github.com/google/uuid v1.6.0 github.com/joho/godotenv v1.5.1 github.com/minio/minio-go/v7 v7.0.69 - github.com/google/uuid v1.6.0 gorm.io/gorm v1.25.8 ) @@ -16,8 +16,6 @@ require ( github.com/cespare/xxhash/v2 v2.2.0 // indirect github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect github.com/dustin/go-humanize v1.0.1 // indirect - github.com/caarlos0/env/v10 v10.0.0 // indirect - github.com/google/uuid v1.6.0 // indirect github.com/jackc/pgpassfile v1.0.0 // indirect github.com/jackc/pgservicefile v0.0.0-20231201235250-de7065d80cb9 // indirect github.com/jackc/pgx/v5 v5.5.5 // indirect @@ -43,7 +41,6 @@ require ( github.com/go-playground/universal-translator v0.18.1 // indirect github.com/go-playground/validator/v10 v10.19.0 // indirect github.com/goccy/go-json v0.10.2 // indirect - github.com/google/uuid v1.6.0 github.com/jinzhu/inflection v1.0.0 // indirect github.com/jinzhu/now v1.1.5 // indirect github.com/json-iterator/go v1.1.12 // indirect diff --git a/main.go b/main.go index 1c85915..15ec832 100644 --- a/main.go +++ b/main.go @@ -19,7 +19,7 @@ import ( type Config struct { // rootFsStorageDSN string `env:"ROOT_FS_STORAGE_DSN,notEmpty"` - VMStateURL string `env:"VM_STATE_URL,notEmpty"` + VMStateURL string `env:"VM_STATE_URL,notEmpty"` FuntionStateStorageDSN string `env:"FUNCTION_STATE_STORAGE_DSN,notEmpty" envDefault:"host=localhost user=postgres password=postgres dbname=postgres port=5432 sslmode=disable TimeZone=Asia/Shanghai"` JWTSecret string `env:"JWT_SECRET,notEmpty"` BuilderEndpoint string `env:"BUILDER_ENDPOINT,notEmpty"` @@ -39,19 +39,19 @@ func main() { redis := database.InitRedis(cfg.VMStateURL) s := &scheduler.Scheduler{ - Redis: redis, + Redis: redis, Context: &ctx, } - //Now inject the scheduler into the routes that need it! + //Now inject the scheduler into the routes that need it! + + go func() { + // every 24 hours we check for + for { + time.Sleep(time.Hour * 6) - go func() { - // every 24 hours we check for - for { - time.Sleep(time.Hour * 6); - log.Println("Ran instance pruning at", time.Now().UTC()) - s.FindAndDestroyUnsused(24); - } + s.FindAndDestroyUnsused(24) + } }() db := database.Init(cfg.FuntionStateStorageDSN)