mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2026-01-04 22:35:48 +08:00
优化代码/增加edge-api goman命令
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
dnsmodels "github.com/TeaOSLab/EdgeAPI/internal/db/models/dns"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/dnsclients"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/dnsclients/dnstypes"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/goman"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/remotelogs"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/utils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/dnsconfigs"
|
||||
@@ -19,7 +20,9 @@ import (
|
||||
|
||||
func init() {
|
||||
dbs.OnReadyDone(func() {
|
||||
go NewDNSTaskExecutor().Start()
|
||||
goman.New(func() {
|
||||
NewDNSTaskExecutor().Start()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -2,19 +2,22 @@ package tasks
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/goman"
|
||||
"github.com/iwind/TeaGo/dbs"
|
||||
"github.com/iwind/TeaGo/logs"
|
||||
"time"
|
||||
)
|
||||
|
||||
func init() {
|
||||
dbs.OnReady(func() {
|
||||
dbs.OnReadyDone(func() {
|
||||
looper := NewEventLooper()
|
||||
go looper.Start()
|
||||
goman.New(func() {
|
||||
looper.Start()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// 事件相关处理程序
|
||||
// EventLooper 事件相关处理程序
|
||||
type EventLooper struct {
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/goman"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/utils"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/utils/numberutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||
@@ -68,14 +69,14 @@ func (this *HealthCheckClusterTask) Run() {
|
||||
return
|
||||
}
|
||||
ticker := utils.NewTicker(duration)
|
||||
go func() {
|
||||
goman.New(func() {
|
||||
for ticker.Wait() {
|
||||
err := this.loop(int64(duration.Seconds()))
|
||||
if err != nil {
|
||||
logs.Println("[TASK][HEALTH_CHECK]" + err.Error())
|
||||
}
|
||||
}
|
||||
}()
|
||||
})
|
||||
this.ticker = ticker
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
teaconst "github.com/TeaOSLab/EdgeAPI/internal/const"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/goman"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/remotelogs"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/utils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/configutils"
|
||||
@@ -116,7 +117,7 @@ func (this *HealthCheckExecutor) Run() ([]*HealthCheckResult, error) {
|
||||
wg := sync.WaitGroup{}
|
||||
wg.Add(countResults)
|
||||
for i := 0; i < countRoutines; i++ {
|
||||
go func() {
|
||||
goman.New(func() {
|
||||
for {
|
||||
select {
|
||||
case result := <-queue:
|
||||
@@ -177,7 +178,7 @@ func (this *HealthCheckExecutor) Run() ([]*HealthCheckResult, error) {
|
||||
return
|
||||
}
|
||||
}
|
||||
}()
|
||||
})
|
||||
}
|
||||
wg.Wait()
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/goman"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/utils"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/utils/numberutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
@@ -14,12 +15,14 @@ import (
|
||||
)
|
||||
|
||||
func init() {
|
||||
dbs.OnReady(func() {
|
||||
go NewHealthCheckTask().Run()
|
||||
dbs.OnReadyDone(func() {
|
||||
goman.New(func() {
|
||||
NewHealthCheckTask().Run()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// 节点健康检查任务
|
||||
// HealthCheckTask 节点健康检查任务
|
||||
type HealthCheckTask struct {
|
||||
tasksMap map[int64]*HealthCheckClusterTask // taskId => task
|
||||
}
|
||||
@@ -83,12 +86,16 @@ func (this *HealthCheckTask) loop() error {
|
||||
oldJSON, _ := json.Marshal(task.Config())
|
||||
if bytes.Compare(oldJSON, newJSON) != 0 {
|
||||
logs.Println("[TASK][HEALTH_CHECK]update cluster '" + numberutils.FormatInt64(clusterId) + "'")
|
||||
go task.Reset(config)
|
||||
goman.New(func() {
|
||||
task.Reset(config)
|
||||
})
|
||||
}
|
||||
} else {
|
||||
task := NewHealthCheckClusterTask(clusterId, config)
|
||||
task = NewHealthCheckClusterTask(clusterId, config)
|
||||
this.tasksMap[clusterId] = task
|
||||
go task.Run()
|
||||
goman.New(func() {
|
||||
task.Run()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/goman"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/utils"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/utils/numberutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/systemconfigs"
|
||||
@@ -13,8 +14,10 @@ import (
|
||||
)
|
||||
|
||||
func init() {
|
||||
dbs.OnReady(func() {
|
||||
go NewLogTask().Run()
|
||||
dbs.OnReadyDone(func() {
|
||||
goman.New(func() {
|
||||
NewLogTask().Run()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@@ -26,8 +29,12 @@ func NewLogTask() *LogTask {
|
||||
}
|
||||
|
||||
func (this *LogTask) Run() {
|
||||
go this.runClean()
|
||||
go this.runMonitor()
|
||||
goman.New(func() {
|
||||
this.runClean()
|
||||
})
|
||||
goman.New(func() {
|
||||
this.runMonitor()
|
||||
})
|
||||
}
|
||||
|
||||
func (this *LogTask) runClean() {
|
||||
|
||||
@@ -2,6 +2,7 @@ package tasks
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/goman"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/utils"
|
||||
"github.com/iwind/TeaGo/dbs"
|
||||
"github.com/iwind/TeaGo/logs"
|
||||
@@ -9,21 +10,23 @@ import (
|
||||
)
|
||||
|
||||
func init() {
|
||||
dbs.OnReady(func() {
|
||||
go NewMessageTask().Run()
|
||||
dbs.OnReadyDone(func() {
|
||||
goman.New(func() {
|
||||
NewMessageTask().Run()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// 消息相关任务
|
||||
// MessageTask 消息相关任务
|
||||
type MessageTask struct {
|
||||
}
|
||||
|
||||
// 获取新对象
|
||||
// NewMessageTask 获取新对象
|
||||
func NewMessageTask() *MessageTask {
|
||||
return &MessageTask{}
|
||||
}
|
||||
|
||||
// 运行
|
||||
// Run 运行
|
||||
func (this *MessageTask) Run() {
|
||||
ticker := utils.NewTicker(24 * time.Hour)
|
||||
for ticker.Wait() {
|
||||
|
||||
@@ -4,6 +4,7 @@ package tasks
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/goman"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/remotelogs"
|
||||
"github.com/iwind/TeaGo/Tea"
|
||||
"github.com/iwind/TeaGo/dbs"
|
||||
@@ -11,8 +12,10 @@ import (
|
||||
)
|
||||
|
||||
func init() {
|
||||
dbs.OnReady(func() {
|
||||
go NewMonitorItemValueTask().Start()
|
||||
dbs.OnReadyDone(func() {
|
||||
goman.New(func() {
|
||||
NewMonitorItemValueTask().Start()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -2,14 +2,17 @@ package tasks
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/goman"
|
||||
"github.com/iwind/TeaGo/dbs"
|
||||
"github.com/iwind/TeaGo/logs"
|
||||
"time"
|
||||
)
|
||||
|
||||
func init() {
|
||||
dbs.OnReady(func() {
|
||||
go NewNodeLogCleanerTask().Start()
|
||||
dbs.OnReadyDone(func() {
|
||||
goman.New(func() {
|
||||
NewNodeLogCleanerTask().Start()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package tasks
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/goman"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/utils/numberutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/systemconfigs"
|
||||
@@ -11,17 +12,17 @@ import (
|
||||
)
|
||||
|
||||
func init() {
|
||||
dbs.OnReady(func() {
|
||||
dbs.OnReadyDone(func() {
|
||||
task := NewNodeMonitorTask(60)
|
||||
ticker := time.NewTicker(60 * time.Second)
|
||||
go func() {
|
||||
goman.New(func() {
|
||||
for range ticker.C {
|
||||
err := task.loop()
|
||||
if err != nil {
|
||||
logs.Println("[TASK][NODE_MONITOR]" + err.Error())
|
||||
}
|
||||
}
|
||||
}()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package tasks
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/goman"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||
"github.com/iwind/TeaGo/dbs"
|
||||
"github.com/iwind/TeaGo/logs"
|
||||
@@ -10,11 +11,13 @@ import (
|
||||
|
||||
func init() {
|
||||
dbs.OnReadyDone(func() {
|
||||
go NewNodeTaskExtractor().Start()
|
||||
goman.New(func() {
|
||||
NewNodeTaskExtractor().Start()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// 节点任务
|
||||
// NodeTaskExtractor 节点任务
|
||||
type NodeTaskExtractor struct {
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package tasks
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/goman"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/utils/numberutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/systemconfigs"
|
||||
@@ -11,17 +12,17 @@ import (
|
||||
)
|
||||
|
||||
func init() {
|
||||
dbs.OnReady(func() {
|
||||
dbs.OnReadyDone(func() {
|
||||
task := NewNSNodeMonitorTask(60)
|
||||
ticker := time.NewTicker(60 * time.Second)
|
||||
go func() {
|
||||
goman.New(func() {
|
||||
for range ticker.C {
|
||||
err := task.loop()
|
||||
if err != nil {
|
||||
logs.Println("[TASK][NS_NODE_MONITOR]" + err.Error())
|
||||
}
|
||||
}
|
||||
}()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/goman"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/systemconfigs"
|
||||
"github.com/iwind/TeaGo/dbs"
|
||||
"github.com/iwind/TeaGo/logs"
|
||||
@@ -14,13 +15,15 @@ import (
|
||||
)
|
||||
|
||||
func init() {
|
||||
dbs.OnReady(func() {
|
||||
dbs.OnReadyDone(func() {
|
||||
task := NewServerAccessLogCleaner()
|
||||
go task.Start()
|
||||
goman.New(func() {
|
||||
task.Start()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// 服务访问日志自动清理
|
||||
// ServerAccessLogCleaner 服务访问日志自动清理
|
||||
type ServerAccessLogCleaner struct {
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package tasks
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models/acme"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/goman"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/utils/numberutils"
|
||||
"github.com/iwind/TeaGo/dbs"
|
||||
"github.com/iwind/TeaGo/logs"
|
||||
@@ -13,8 +14,10 @@ import (
|
||||
)
|
||||
|
||||
func init() {
|
||||
dbs.OnReady(func() {
|
||||
go NewSSLCertExpireCheckExecutor().Start()
|
||||
dbs.OnReadyDone(func() {
|
||||
goman.New(func() {
|
||||
NewSSLCertExpireCheckExecutor().Start()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user