diff --git a/backend/constant/website.go b/backend/constant/website.go index ea400ce96..06fdba702 100644 --- a/backend/constant/website.go +++ b/backend/constant/website.go @@ -4,8 +4,9 @@ const ( WebRunning = "Running" WebStopped = "Stopped" - DateLayout = "2006-01-02" - DefaultDate = "1970-01-01" + DateLayout = "2006-01-02" + DateTimeLayout = "2006-01-02 15:04:05" + DefaultDate = "1970-01-01" ProtocolHTTP = "HTTP" ProtocolHTTPS = "HTTPS" diff --git a/backend/cron/job/ssl.go b/backend/cron/job/ssl.go index 8792cbc06..c5d122d88 100644 --- a/backend/cron/job/ssl.go +++ b/backend/cron/job/ssl.go @@ -3,6 +3,7 @@ package job import ( "github.com/1Panel-dev/1Panel/backend/app/repo" "github.com/1Panel-dev/1Panel/backend/app/service" + "github.com/1Panel-dev/1Panel/backend/constant" "github.com/1Panel-dev/1Panel/backend/global" "time" ) @@ -19,13 +20,16 @@ func (ssl *ssl) Run() { sslService := service.NewIWebsiteSSLService() sslList, _ := sslRepo.List() global.LOG.Info("ssl renew cron job start...") - now := time.Now() + now := time.Now().Add(10 * time.Second) for _, s := range sslList { if !s.AutoRenew || s.Provider == "manual" || s.Provider == "dnsManual" { continue } - sum := s.ExpireDate.Sub(now) - if sum.Hours() < 168 { + expireDate, _ := time.ParseInLocation(constant.DateTimeLayout, s.ExpireDate.String(), time.Now().Location()) + sum := expireDate.Sub(now) + global.LOG.Info(expireDate) + global.LOG.Info(sum.Hours()) + if sum.Hours() < 720 { if err := sslService.Renew(s.ID); err != nil { global.LOG.Errorf("renew doamin [%s] ssl failed err:%s", s.PrimaryDomain, err.Error()) } diff --git a/backend/cron/job/website.go b/backend/cron/job/website.go index 291a94fe8..7861ad08c 100644 --- a/backend/cron/job/website.go +++ b/backend/cron/job/website.go @@ -20,7 +20,7 @@ func NewWebsiteJob() *website { func (w *website) Run() { websites, _ := repo.NewIWebsiteRepo().List() global.LOG.Info("website cron job start...") - now := time.Now() + now := time.Now().Add(10 * time.Second) if len(websites) > 0 { neverExpireDate, _ := time.Parse(constant.DateLayout, constant.DefaultDate) var wg sync.WaitGroup @@ -28,7 +28,8 @@ func (w *website) Run() { if site.Status != constant.WebRunning || neverExpireDate.Equal(site.ExpireDate) { continue } - if site.ExpireDate.Before(now) { + expireDate, _ := time.ParseInLocation(constant.DateTimeLayout, site.ExpireDate.String(), time.Now().Location()) + if expireDate.Before(now) { wg.Add(1) go func(ws model.Website) { stopWebsite(ws.ID, &wg)