fix cron timezone #1648

This commit is contained in:
Alireza Ahmadi 2026-10-09 21:30:03 +02:00
parent f1b4b751ee
commit 982d996e89
2 changed files with 14 additions and 5 deletions

View file

@ -135,6 +135,10 @@ func (s *AllSetting) CheckValid() error {
return err
}
if _, err := cronspec.Parse(s.TgRunTime); err != nil {
return err
}
_, err := time.LoadLocation(s.TimeLocation)
if err != nil {
return common.NewError("time location not exist:", s.TimeLocation)

View file

@ -280,14 +280,19 @@ func (s *Server) startTask() {
if (err == nil) && (isTgbotenabled) {
runtime, err := s.settingService.GetTgbotRuntime()
if err != nil || runtime == "" {
logger.Errorf("Add NewStatsNotifyJob error[%s], Runtime[%s] invalid, will run default", err, runtime)
logger.Errorf("Add NewStatsNotifyJob error[%v], Runtime[%s] invalid, will run default", err, runtime)
runtime = "@daily"
}
logger.Infof("Tg notify enabled,run at %s", runtime)
_, err = s.cron.AddJob(runtime, job.NewStatsNotifyJob())
// The scheduler's own parser demands a seconds field, so hand it the
// schedule already parsed to accept standard five-field crontab too.
schedule, err := cronspec.Parse(runtime)
if err != nil {
logger.Warning("Add NewStatsNotifyJob error", err)
return
logger.Warning("Add NewStatsNotifyJob error, will run default:", err)
schedule, _ = cronspec.Parse("@daily")
}
if schedule != nil {
logger.Infof("Tg notify enabled,run at %s", runtime)
s.cron.Schedule(schedule, job.NewStatsNotifyJob())
}
// Check CPU load and alarm to TgBot if threshold passes