mirror of
https://github.com/tgdrive/teldrive.git
synced 2024-09-20 08:15:55 +08:00
feat: added option to disable cron jobs
This commit is contained in:
parent
f33b0428e7
commit
1353ae7bd2
|
@ -27,6 +27,7 @@ import (
|
|||
"github.com/gin-contrib/pprof"
|
||||
ginzap "github.com/gin-contrib/zap"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/go-co-op/gocron"
|
||||
"github.com/mitchellh/go-homedir"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/pflag"
|
||||
|
@ -54,6 +55,8 @@ func NewRun() *cobra.Command {
|
|||
duration.DurationVar(runCmd.Flags(), &config.Server.GracefulShutdown, "server-graceful-shutdown", 15*time.Second, "Server graceful shutdown timeout")
|
||||
runCmd.Flags().BoolVar(&config.Server.EnablePprof, "server-enable-pprof", false, "Enable Pprof Profiling")
|
||||
|
||||
runCmd.Flags().BoolVar(&config.CronJobs.Enable, "cronjobs-enable", true, "Run cron jobs")
|
||||
|
||||
runCmd.Flags().IntVarP(&config.Log.Level, "log-level", "", -1, "Logging level")
|
||||
runCmd.Flags().StringVar(&config.Log.File, "log-file", "", "Logging file path")
|
||||
runCmd.Flags().BoolVar(&config.Log.Development, "log-development", false, "Enable development mode")
|
||||
|
@ -120,8 +123,11 @@ func runApplication(conf *config.Config) {
|
|||
cancel()
|
||||
}()
|
||||
|
||||
scheduler := gocron.NewScheduler(time.UTC)
|
||||
|
||||
app := fx.New(
|
||||
fx.Supply(conf),
|
||||
fx.Supply(scheduler),
|
||||
fx.Supply(logging.DefaultLogger().Desugar()),
|
||||
fx.NopLogger,
|
||||
fx.StopTimeout(conf.Server.GracefulShutdown+time.Second),
|
||||
|
|
|
@ -8,6 +8,9 @@
|
|||
max-lifetime = "10m"
|
||||
max-open-connections = 25
|
||||
|
||||
[cronjobs]
|
||||
enable = true
|
||||
|
||||
[jwt]
|
||||
allowed-users = [""]
|
||||
secret = ""
|
||||
|
|
|
@ -5,11 +5,12 @@ import (
|
|||
)
|
||||
|
||||
type Config struct {
|
||||
Server ServerConfig
|
||||
Log LoggingConfig
|
||||
JWT JWTConfig
|
||||
DB DBConfig
|
||||
TG TGConfig
|
||||
Server ServerConfig
|
||||
Log LoggingConfig
|
||||
JWT JWTConfig
|
||||
DB DBConfig
|
||||
TG TGConfig
|
||||
CronJobs CronJobConfig
|
||||
}
|
||||
|
||||
type ServerConfig struct {
|
||||
|
@ -18,6 +19,10 @@ type ServerConfig struct {
|
|||
EnablePprof bool
|
||||
}
|
||||
|
||||
type CronJobConfig struct {
|
||||
Enable bool
|
||||
}
|
||||
|
||||
type TGConfig struct {
|
||||
AppId int
|
||||
AppHash string
|
||||
|
|
|
@ -41,9 +41,10 @@ type CronService struct {
|
|||
logger *zap.SugaredLogger
|
||||
}
|
||||
|
||||
func StartCronJobs(db *gorm.DB, cnf *config.Config) {
|
||||
scheduler := gocron.NewScheduler(time.UTC)
|
||||
|
||||
func StartCronJobs(scheduler *gocron.Scheduler, db *gorm.DB, cnf *config.Config) {
|
||||
if !cnf.CronJobs.Enable {
|
||||
return
|
||||
}
|
||||
ctx := context.Background()
|
||||
|
||||
cron := CronService{db: db, cnf: cnf, logger: logging.DefaultLogger()}
|
||||
|
|
Loading…
Reference in a new issue