-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
website.go
53 lines (48 loc) · 1.29 KB
/
website.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package job
import (
"github.com/1Panel-dev/1Panel/backend/app/dto/request"
"github.com/1Panel-dev/1Panel/backend/app/model"
"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"
"sync"
"time"
)
type website struct{}
func NewWebsiteJob() *website {
return &website{}
}
func (w *website) Run() {
websites, _ := repo.NewIWebsiteRepo().List()
global.LOG.Info("website cron job start...")
now := time.Now()
if len(websites) > 0 {
neverExpireDate, _ := time.Parse(constant.DateLayout, constant.DefaultDate)
var wg sync.WaitGroup
for _, site := range websites {
if site.Status != constant.WebRunning || neverExpireDate.Equal(site.ExpireDate) {
continue
}
if site.ExpireDate.Before(now) {
wg.Add(1)
go func(ws model.Website) {
stopWebsite(ws.ID, &wg)
}(site)
}
}
wg.Wait()
}
global.LOG.Info("website cron job end...")
}
func stopWebsite(websiteId uint, wg *sync.WaitGroup) {
websiteService := service.NewWebsiteService()
req := request.WebsiteOp{
ID: websiteId,
Operate: constant.StopWeb,
}
if err := websiteService.OpWebsite(req); err != nil {
global.LOG.Errorf("stop website err: %s", err.Error())
}
wg.Done()
}