|
|
|
@ -7,6 +7,7 @@ import (
|
|
|
|
|
"github.com/1Panel-dev/1Panel/backend/app/service" |
|
|
|
|
"github.com/1Panel-dev/1Panel/backend/constant" |
|
|
|
|
"github.com/1Panel-dev/1Panel/backend/global" |
|
|
|
|
"github.com/1Panel-dev/1Panel/backend/utils/common" |
|
|
|
|
"sync" |
|
|
|
|
"time" |
|
|
|
|
) |
|
|
|
@ -18,8 +19,9 @@ func NewWebsiteJob() *website {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (w *website) Run() { |
|
|
|
|
nyc, _ := time.LoadLocation(common.LoadTimeZone()) |
|
|
|
|
websites, _ := repo.NewIWebsiteRepo().List() |
|
|
|
|
global.LOG.Info("website cron job start...") |
|
|
|
|
global.LOG.Info("Website scheduled task in progress ...") |
|
|
|
|
now := time.Now().Add(10 * time.Second) |
|
|
|
|
if len(websites) > 0 { |
|
|
|
|
neverExpireDate, _ := time.Parse(constant.DateLayout, constant.DefaultDate) |
|
|
|
@ -28,27 +30,29 @@ func (w *website) Run() {
|
|
|
|
|
if site.Status != constant.WebRunning || neverExpireDate.Equal(site.ExpireDate) { |
|
|
|
|
continue |
|
|
|
|
} |
|
|
|
|
expireDate, _ := time.ParseInLocation(constant.DateTimeLayout, site.ExpireDate.String(), time.Now().Location()) |
|
|
|
|
expireDate, _ := time.ParseInLocation(constant.DateTimeLayout, site.ExpireDate.String(), nyc) |
|
|
|
|
if expireDate.Before(now) { |
|
|
|
|
wg.Add(1) |
|
|
|
|
go func(ws model.Website) { |
|
|
|
|
stopWebsite(ws.ID, &wg) |
|
|
|
|
stopWebsite(ws.ID, ws.PrimaryDomain, &wg) |
|
|
|
|
}(site) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
wg.Wait() |
|
|
|
|
} |
|
|
|
|
global.LOG.Info("website cron job end...") |
|
|
|
|
global.LOG.Info("Website scheduled task has completed") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func stopWebsite(websiteId uint, wg *sync.WaitGroup) { |
|
|
|
|
func stopWebsite(websiteId uint, websiteName string, wg *sync.WaitGroup) { |
|
|
|
|
websiteService := service.NewIWebsiteService() |
|
|
|
|
req := request.WebsiteOp{ |
|
|
|
|
ID: websiteId, |
|
|
|
|
Operate: constant.StopWeb, |
|
|
|
|
} |
|
|
|
|
if err := websiteService.OpWebsite(req); err != nil { |
|
|
|
|
global.LOG.Errorf("stop website err: %s", err.Error()) |
|
|
|
|
global.LOG.Errorf("Website [%s] seop failed err %v", websiteName, err) |
|
|
|
|
} else { |
|
|
|
|
global.LOG.Infof("Website [%s] stopped successfully", websiteName) |
|
|
|
|
} |
|
|
|
|
wg.Done() |
|
|
|
|
} |
|
|
|
|