mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-03 15:00:27 +08:00
优化代码/增加edge-api goman命令
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/iwind/TeaGo/Tea"
|
||||
_ "github.com/iwind/TeaGo/bootstrap"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
"github.com/iwind/gosock/pkg/gosock"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
@@ -68,6 +69,20 @@ func main() {
|
||||
}
|
||||
fmt.Println("done")
|
||||
})
|
||||
app.On("goman", func() {
|
||||
var sock = gosock.NewTmpSock(teaconst.ProcessName)
|
||||
reply, err := sock.Send(&gosock.Command{Code: "goman"})
|
||||
if err != nil {
|
||||
fmt.Println("[ERROR]" + err.Error())
|
||||
} else {
|
||||
instancesJSON, err := json.MarshalIndent(reply.Params, "", " ")
|
||||
if err != nil {
|
||||
fmt.Println("[ERROR]" + err.Error())
|
||||
} else {
|
||||
fmt.Println(string(instancesJSON))
|
||||
}
|
||||
}
|
||||
})
|
||||
app.Run(func() {
|
||||
nodes.NewAPINode().Start()
|
||||
})
|
||||
|
||||
@@ -3,6 +3,7 @@ package accounts
|
||||
import (
|
||||
"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/EdgeCommon/pkg/userconfigs"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
@@ -16,7 +17,7 @@ import (
|
||||
|
||||
func init() {
|
||||
dbs.OnReadyDone(func() {
|
||||
go func() {
|
||||
goman.New(func() {
|
||||
// 自动支付账单任务
|
||||
var ticker = time.NewTicker(12 * time.Hour)
|
||||
for range ticker.C {
|
||||
@@ -29,7 +30,7 @@ func init() {
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package models
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/goman"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/remotelogs"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||
"github.com/iwind/TeaGo/dbs"
|
||||
@@ -49,7 +50,9 @@ type NSAccessLogDAOWrapper struct {
|
||||
func init() {
|
||||
initializer := NewDBNodeInitializer()
|
||||
dbs.OnReadyDone(func() {
|
||||
go initializer.Start()
|
||||
goman.New(func() {
|
||||
initializer.Start()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package models
|
||||
import (
|
||||
teaconst "github.com/TeaOSLab/EdgeAPI/internal/const"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/goman"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/remotelogs"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
@@ -46,14 +47,14 @@ func init() {
|
||||
dbs.OnReadyDone(func() {
|
||||
// 清理数据任务
|
||||
var ticker = time.NewTicker(time.Duration(rands.Int(24, 48)) * time.Hour)
|
||||
go func() {
|
||||
goman.New(func() {
|
||||
for range ticker.C {
|
||||
err := SharedMessageTaskDAO.CleanExpiredMessageTasks(nil, 30) // 只保留30天
|
||||
if err != nil {
|
||||
remotelogs.Error("SharedMessageTaskDAO", "clean expired data failed: "+err.Error())
|
||||
}
|
||||
}
|
||||
}()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/goman"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/remotelogs"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/iwind/TeaGo/Tea"
|
||||
@@ -16,14 +17,14 @@ func init() {
|
||||
dbs.OnReadyDone(func() {
|
||||
// 清理数据任务
|
||||
var ticker = time.NewTicker(time.Duration(rands.Int(24, 48)) * time.Hour)
|
||||
go func() {
|
||||
goman.New(func() {
|
||||
for range ticker.C {
|
||||
err := SharedMessageTaskLogDAO.CleanExpiredLogs(nil, 30) // 只保留30天
|
||||
if err != nil {
|
||||
remotelogs.Error("SharedMessageTaskLogDAO", "clean expired data failed: "+err.Error())
|
||||
}
|
||||
}
|
||||
}()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package models
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/goman"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/iwind/TeaGo/Tea"
|
||||
@@ -21,14 +22,14 @@ func init() {
|
||||
dbs.OnReadyDone(func() {
|
||||
// 清理数据任务
|
||||
var ticker = time.NewTicker(time.Duration(rands.Int(24, 48)) * time.Hour)
|
||||
go func() {
|
||||
goman.New(func() {
|
||||
for range ticker.C {
|
||||
err := SharedMetricStatDAO.Clean(nil)
|
||||
if err != nil {
|
||||
logs.Println("SharedMetricStatDAO: clean expired data failed: " + err.Error())
|
||||
}
|
||||
}
|
||||
}()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/goman"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/iwind/TeaGo/Tea"
|
||||
@@ -18,14 +19,14 @@ func init() {
|
||||
dbs.OnReadyDone(func() {
|
||||
// 清理数据任务
|
||||
var ticker = time.NewTicker(time.Duration(rands.Int(24, 48)) * time.Hour)
|
||||
go func() {
|
||||
goman.New(func() {
|
||||
for range ticker.C {
|
||||
err := SharedMetricSumStatDAO.Clean(nil)
|
||||
if err != nil {
|
||||
logs.Println("SharedMetricSumStatDAO: clean expired data failed: " + err.Error())
|
||||
}
|
||||
}
|
||||
}()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package nameservers
|
||||
|
||||
import (
|
||||
"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/go-sql-driver/mysql"
|
||||
@@ -19,14 +20,14 @@ func init() {
|
||||
dbs.OnReadyDone(func() {
|
||||
// 清理数据任务
|
||||
var ticker = time.NewTicker(time.Duration(rands.Int(24, 48)) * time.Hour)
|
||||
go func() {
|
||||
goman.New(func() {
|
||||
for range ticker.C {
|
||||
err := SharedNSRecordHourlyStatDAO.Clean(nil, 30) // 只保留N天
|
||||
if err != nil {
|
||||
remotelogs.Error("NodeClusterTrafficDailyStatDAO", "clean expired data failed: "+err.Error())
|
||||
}
|
||||
}
|
||||
}()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package models
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/goman"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/utils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
@@ -21,14 +22,14 @@ func init() {
|
||||
dbs.OnReadyDone(func() {
|
||||
// 清理数据任务
|
||||
var ticker = time.NewTicker(time.Duration(rands.Int(24, 48)) * time.Hour)
|
||||
go func() {
|
||||
goman.New(func() {
|
||||
for range ticker.C {
|
||||
err := SharedServerDailyStatDAO.Clean(nil, 30) // 只保留N天
|
||||
if err != nil {
|
||||
logs.Println("ServerDailyStatDAO", "clean expired data failed: "+err.Error())
|
||||
}
|
||||
}
|
||||
}()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package stats
|
||||
|
||||
import (
|
||||
"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/go-sql-driver/mysql"
|
||||
@@ -19,14 +20,14 @@ func init() {
|
||||
dbs.OnReadyDone(func() {
|
||||
// 清理数据任务
|
||||
var ticker = time.NewTicker(time.Duration(rands.Int(24, 48)) * time.Hour)
|
||||
go func() {
|
||||
goman.New(func() {
|
||||
for range ticker.C {
|
||||
err := SharedNodeClusterTrafficDailyStatDAO.Clean(nil, 30) // 只保留N天
|
||||
if err != nil {
|
||||
remotelogs.Error("NodeClusterTrafficDailyStatDAO", "clean expired data failed: "+err.Error())
|
||||
}
|
||||
}
|
||||
}()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package stats
|
||||
|
||||
import (
|
||||
"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/go-sql-driver/mysql"
|
||||
@@ -19,14 +20,14 @@ func init() {
|
||||
dbs.OnReadyDone(func() {
|
||||
// 清理数据任务
|
||||
var ticker = time.NewTicker(time.Duration(rands.Int(24, 48)) * time.Hour)
|
||||
go func() {
|
||||
goman.New(func() {
|
||||
for range ticker.C {
|
||||
err := SharedNodeTrafficDailyStatDAO.Clean(nil, 30) // 只保留N天
|
||||
if err != nil {
|
||||
remotelogs.Error("NodeTrafficDailyStatDAO", "clean expired data failed: "+err.Error())
|
||||
}
|
||||
}
|
||||
}()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package stats
|
||||
|
||||
import (
|
||||
"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/go-sql-driver/mysql"
|
||||
@@ -19,14 +20,14 @@ func init() {
|
||||
dbs.OnReadyDone(func() {
|
||||
// 清理数据任务
|
||||
var ticker = time.NewTicker(time.Duration(rands.Int(24, 48)) * time.Hour)
|
||||
go func() {
|
||||
goman.New(func() {
|
||||
for range ticker.C {
|
||||
err := SharedNodeTrafficHourlyStatDAO.Clean(nil, 15) // 只保留N天
|
||||
if err != nil {
|
||||
remotelogs.Error("NodeTrafficHourlyStatDAO", "clean expired data failed: "+err.Error())
|
||||
}
|
||||
}
|
||||
}()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package stats
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/goman"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/remotelogs"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/iwind/TeaGo/Tea"
|
||||
@@ -16,14 +17,14 @@ func init() {
|
||||
dbs.OnReadyDone(func() {
|
||||
// 清理数据任务
|
||||
var ticker = time.NewTicker(time.Duration(rands.Int(24, 48)) * time.Hour)
|
||||
go func() {
|
||||
goman.New(func() {
|
||||
for range ticker.C {
|
||||
err := SharedServerClientBrowserMonthlyStatDAO.Clean(nil)
|
||||
if err != nil {
|
||||
remotelogs.Error("ServerClientBrowserMonthlyStatDAO", "clean expired data failed: "+err.Error())
|
||||
}
|
||||
}
|
||||
}()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package stats
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/goman"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/remotelogs"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/iwind/TeaGo/Tea"
|
||||
@@ -16,14 +17,14 @@ func init() {
|
||||
dbs.OnReadyDone(func() {
|
||||
// 清理数据任务
|
||||
var ticker = time.NewTicker(time.Duration(rands.Int(24, 48)) * time.Hour)
|
||||
go func() {
|
||||
goman.New(func() {
|
||||
for range ticker.C {
|
||||
err := SharedServerClientSystemMonthlyStatDAO.Clean(nil)
|
||||
if err != nil {
|
||||
remotelogs.Error("ServerClientSystemMonthlyStatDAO", "clean expired data failed: "+err.Error())
|
||||
}
|
||||
}
|
||||
}()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package stats
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/goman"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/remotelogs"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/iwind/TeaGo/Tea"
|
||||
@@ -22,14 +23,14 @@ func init() {
|
||||
dbs.OnReadyDone(func() {
|
||||
// 清理数据任务
|
||||
var ticker = time.NewTicker(time.Duration(rands.Int(24, 48)) * time.Hour)
|
||||
go func() {
|
||||
goman.New(func() {
|
||||
for range ticker.C {
|
||||
err := SharedServerDomainHourlyStatDAO.Clean(nil, 7) // 只保留7天
|
||||
if err != nil {
|
||||
remotelogs.Error("ServerDomainHourlyStatDAO", "clean expired data failed: "+err.Error())
|
||||
}
|
||||
}
|
||||
}()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package stats
|
||||
import (
|
||||
"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/go-sql-driver/mysql"
|
||||
"github.com/iwind/TeaGo/Tea"
|
||||
@@ -19,14 +20,14 @@ func init() {
|
||||
dbs.OnReadyDone(func() {
|
||||
// 清理数据任务
|
||||
var ticker = time.NewTicker(time.Duration(rands.Int(24, 48)) * time.Hour)
|
||||
go func() {
|
||||
goman.New(func() {
|
||||
for range ticker.C {
|
||||
err := SharedServerHTTPFirewallDailyStatDAO.Clean(nil, 30) // 只保留N天
|
||||
if err != nil {
|
||||
remotelogs.Error("ServerHTTPFirewallDailyStatDAO", "clean expired data failed: "+err.Error())
|
||||
}
|
||||
}
|
||||
}()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package stats
|
||||
import (
|
||||
"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/go-sql-driver/mysql"
|
||||
"github.com/iwind/TeaGo/Tea"
|
||||
@@ -19,14 +20,14 @@ func init() {
|
||||
dbs.OnReadyDone(func() {
|
||||
// 清理数据任务
|
||||
var ticker = time.NewTicker(time.Duration(rands.Int(24, 48)) * time.Hour)
|
||||
go func() {
|
||||
goman.New(func() {
|
||||
for range ticker.C {
|
||||
err := SharedServerHTTPFirewallHourlyStatDAO.Clean(nil, 15) // 只保留N天
|
||||
if err != nil {
|
||||
remotelogs.Error("ServerHTTPFirewallHourlyStatDAO", "clean expired data failed: "+err.Error())
|
||||
}
|
||||
}
|
||||
}()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package stats
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models/regions"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/goman"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/remotelogs"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/iwind/TeaGo/Tea"
|
||||
@@ -17,14 +18,14 @@ func init() {
|
||||
dbs.OnReadyDone(func() {
|
||||
// 清理数据任务
|
||||
var ticker = time.NewTicker(time.Duration(rands.Int(24, 48)) * time.Hour)
|
||||
go func() {
|
||||
goman.New(func() {
|
||||
for range ticker.C {
|
||||
err := SharedServerRegionCityMonthlyStatDAO.Clean(nil)
|
||||
if err != nil {
|
||||
remotelogs.Error("SharedServerRegionCityMonthlyStatDAO", "clean expired data failed: "+err.Error())
|
||||
}
|
||||
}
|
||||
}()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package stats
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/goman"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/remotelogs"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/iwind/TeaGo/Tea"
|
||||
@@ -16,14 +17,14 @@ func init() {
|
||||
dbs.OnReadyDone(func() {
|
||||
// 清理数据任务
|
||||
var ticker = time.NewTicker(time.Duration(rands.Int(24, 48)) * time.Hour)
|
||||
go func() {
|
||||
goman.New(func() {
|
||||
for range ticker.C {
|
||||
err := SharedServerRegionCountryDailyStatDAO.Clean(nil)
|
||||
if err != nil {
|
||||
remotelogs.Error("ServerRegionCountryDailyStatDAO", "clean expired data failed: "+err.Error())
|
||||
}
|
||||
}
|
||||
}()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package stats
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/goman"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/remotelogs"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/iwind/TeaGo/Tea"
|
||||
@@ -16,14 +17,14 @@ func init() {
|
||||
dbs.OnReadyDone(func() {
|
||||
// 清理数据任务
|
||||
var ticker = time.NewTicker(time.Duration(rands.Int(24, 48)) * time.Hour)
|
||||
go func() {
|
||||
goman.New(func() {
|
||||
for range ticker.C {
|
||||
err := SharedServerRegionCountryMonthlyStatDAO.Clean(nil)
|
||||
if err != nil {
|
||||
remotelogs.Error("SharedServerRegionCountryMonthlyStatDAO", "clean expired data failed: "+err.Error())
|
||||
}
|
||||
}
|
||||
}()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package stats
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/goman"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/remotelogs"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/iwind/TeaGo/Tea"
|
||||
@@ -16,14 +17,14 @@ func init() {
|
||||
dbs.OnReadyDone(func() {
|
||||
// 清理数据任务
|
||||
var ticker = time.NewTicker(time.Duration(rands.Int(24, 48)) * time.Hour)
|
||||
go func() {
|
||||
goman.New(func() {
|
||||
for range ticker.C {
|
||||
err := SharedServerRegionProviderMonthlyStatDAO.Clean(nil)
|
||||
if err != nil {
|
||||
remotelogs.Error("SharedServerRegionProviderMonthlyStatDAO", "clean expired data failed: "+err.Error())
|
||||
}
|
||||
}
|
||||
}()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package stats
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models/regions"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/goman"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/remotelogs"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/iwind/TeaGo/Tea"
|
||||
@@ -17,14 +18,14 @@ func init() {
|
||||
dbs.OnReadyDone(func() {
|
||||
// 清理数据任务
|
||||
var ticker = time.NewTicker(time.Duration(rands.Int(24, 48)) * time.Hour)
|
||||
go func() {
|
||||
goman.New(func() {
|
||||
for range ticker.C {
|
||||
err := SharedServerRegionProvinceMonthlyStatDAO.Clean(nil)
|
||||
if err != nil {
|
||||
remotelogs.Error("SharedServerRegionProvinceMonthlyStatDAO", "clean expired data failed: "+err.Error())
|
||||
}
|
||||
}
|
||||
}()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package stats
|
||||
|
||||
import (
|
||||
"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/go-sql-driver/mysql"
|
||||
@@ -19,14 +20,14 @@ func init() {
|
||||
dbs.OnReadyDone(func() {
|
||||
// 清理数据任务
|
||||
var ticker = time.NewTicker(time.Duration(rands.Int(24, 48)) * time.Hour)
|
||||
go func() {
|
||||
goman.New(func() {
|
||||
for range ticker.C {
|
||||
err := SharedTrafficDailyStatDAO.Clean(nil, 30) // 只保留N天
|
||||
if err != nil {
|
||||
remotelogs.Error("TrafficDailyStatDAO", "clean expired data failed: "+err.Error())
|
||||
}
|
||||
}
|
||||
}()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package stats
|
||||
|
||||
import (
|
||||
"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/go-sql-driver/mysql"
|
||||
@@ -19,14 +20,14 @@ func init() {
|
||||
dbs.OnReadyDone(func() {
|
||||
// 清理数据任务
|
||||
var ticker = time.NewTicker(time.Duration(rands.Int(24, 48)) * time.Hour)
|
||||
go func() {
|
||||
goman.New(func() {
|
||||
for range ticker.C {
|
||||
err := SharedTrafficHourlyStatDAO.Clean(nil, 15) // 只保留N天
|
||||
if err != nil {
|
||||
remotelogs.Error("TrafficHourlyStatDAO", "clean expired data failed: "+err.Error())
|
||||
}
|
||||
}
|
||||
}()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package models
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/goman"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/remotelogs"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/utils/numberutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
@@ -20,7 +21,7 @@ func init() {
|
||||
dbs.OnReadyDone(func() {
|
||||
var generatedMonths = []string{}
|
||||
|
||||
go func() {
|
||||
goman.New(func() {
|
||||
// 自动生成账单任务
|
||||
var ticker = time.NewTicker(1 * time.Minute)
|
||||
for range ticker.C {
|
||||
@@ -37,7 +38,7 @@ func init() {
|
||||
generatedMonths = append(generatedMonths, lastMonth)
|
||||
}
|
||||
}
|
||||
}()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
12
internal/goman/instance.go
Normal file
12
internal/goman/instance.go
Normal file
@@ -0,0 +1,12 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package goman
|
||||
|
||||
import "time"
|
||||
|
||||
type Instance struct {
|
||||
Id uint64
|
||||
CreatedTime time.Time
|
||||
File string
|
||||
Line int
|
||||
}
|
||||
81
internal/goman/lib.go
Normal file
81
internal/goman/lib.go
Normal file
@@ -0,0 +1,81 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package goman
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
var locker = &sync.Mutex{}
|
||||
var instanceMap = map[uint64]*Instance{} // id => *Instance
|
||||
var instanceId = uint64(0)
|
||||
|
||||
// New 新创建goroutine
|
||||
func New(f func()) {
|
||||
_, file, line, _ := runtime.Caller(1)
|
||||
|
||||
go func() {
|
||||
locker.Lock()
|
||||
instanceId++
|
||||
|
||||
var instance = &Instance{
|
||||
Id: instanceId,
|
||||
CreatedTime: time.Now(),
|
||||
}
|
||||
|
||||
instance.File = file
|
||||
instance.Line = line
|
||||
|
||||
instanceMap[instanceId] = instance
|
||||
locker.Unlock()
|
||||
|
||||
// run function
|
||||
f()
|
||||
|
||||
locker.Lock()
|
||||
delete(instanceMap, instanceId)
|
||||
locker.Unlock()
|
||||
}()
|
||||
}
|
||||
|
||||
// NewWithArgs 创建带有参数的goroutine
|
||||
func NewWithArgs(f func(args ...interface{}), args ...interface{}) {
|
||||
_, file, line, _ := runtime.Caller(1)
|
||||
|
||||
go func() {
|
||||
locker.Lock()
|
||||
instanceId++
|
||||
|
||||
var instance = &Instance{
|
||||
Id: instanceId,
|
||||
CreatedTime: time.Now(),
|
||||
}
|
||||
|
||||
instance.File = file
|
||||
instance.Line = line
|
||||
|
||||
instanceMap[instanceId] = instance
|
||||
locker.Unlock()
|
||||
|
||||
// run function
|
||||
f(args...)
|
||||
|
||||
locker.Lock()
|
||||
delete(instanceMap, instanceId)
|
||||
locker.Unlock()
|
||||
}()
|
||||
}
|
||||
|
||||
// List 列出所有正在运行goroutine
|
||||
func List() []*Instance {
|
||||
locker.Lock()
|
||||
defer locker.Unlock()
|
||||
|
||||
var result = []*Instance{}
|
||||
for _, instance := range instanceMap {
|
||||
result = append(result, instance)
|
||||
}
|
||||
return result
|
||||
}
|
||||
28
internal/goman/lib_test.go
Normal file
28
internal/goman/lib_test.go
Normal file
@@ -0,0 +1,28 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package goman
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestNew(t *testing.T) {
|
||||
New(func() {
|
||||
t.Log("Hello")
|
||||
|
||||
t.Log(List())
|
||||
})
|
||||
|
||||
time.Sleep(1 * time.Second)
|
||||
t.Log(List())
|
||||
|
||||
time.Sleep(1 * time.Second)
|
||||
}
|
||||
|
||||
func TestNewWithArgs(t *testing.T) {
|
||||
NewWithArgs(func(args ...interface{}) {
|
||||
t.Log(args[0], args[1])
|
||||
}, 1, 2)
|
||||
time.Sleep(1 * time.Second)
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"errors"
|
||||
"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/nodeconfigs"
|
||||
@@ -37,7 +38,7 @@ func (this *NodeQueue) InstallNodeProcess(nodeId int64, isUpgrading bool) error
|
||||
|
||||
// 更新时间
|
||||
ticker := utils.NewTicker(3 * time.Second)
|
||||
go func() {
|
||||
goman.New(func() {
|
||||
for ticker.Wait() {
|
||||
installStatus.UpdatedAt = time.Now().Unix()
|
||||
err := models.SharedNodeDAO.UpdateNodeInstallStatus(nil, nodeId, installStatus)
|
||||
@@ -46,7 +47,7 @@ func (this *NodeQueue) InstallNodeProcess(nodeId int64, isUpgrading bool) error
|
||||
continue
|
||||
}
|
||||
}
|
||||
}()
|
||||
})
|
||||
defer func() {
|
||||
ticker.Stop()
|
||||
}()
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"errors"
|
||||
"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/nodeconfigs"
|
||||
@@ -37,7 +38,7 @@ func (this *NSNodeQueue) InstallNodeProcess(nodeId int64, isUpgrading bool) erro
|
||||
|
||||
// 更新时间
|
||||
ticker := utils.NewTicker(3 * time.Second)
|
||||
go func() {
|
||||
goman.New(func() {
|
||||
for ticker.Wait() {
|
||||
installStatus.UpdatedAt = time.Now().Unix()
|
||||
err := models.SharedNSNodeDAO.UpdateNodeInstallStatus(nil, nodeId, installStatus)
|
||||
@@ -46,7 +47,7 @@ func (this *NSNodeQueue) InstallNodeProcess(nodeId int64, isUpgrading bool) erro
|
||||
continue
|
||||
}
|
||||
}
|
||||
}()
|
||||
})
|
||||
defer func() {
|
||||
ticker.Stop()
|
||||
}()
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/goman"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
"github.com/iwind/TeaGo/Tea"
|
||||
"github.com/iwind/TeaGo/dbs"
|
||||
@@ -19,27 +20,27 @@ func init() {
|
||||
})
|
||||
}
|
||||
|
||||
// IP库更新程序
|
||||
// Updater IP库更新程序
|
||||
type Updater struct {
|
||||
}
|
||||
|
||||
// 获取新对象
|
||||
// NewUpdater 获取新对象
|
||||
func NewUpdater() *Updater {
|
||||
return &Updater{}
|
||||
}
|
||||
|
||||
// 开始更新
|
||||
// Start 开始更新
|
||||
func (this *Updater) Start() {
|
||||
// 这里不需要太频繁检查更新,因为通常不需要更新IP库
|
||||
ticker := time.NewTicker(1 * time.Hour)
|
||||
go func() {
|
||||
goman.New(func() {
|
||||
for range ticker.C {
|
||||
err := this.loop()
|
||||
if err != nil {
|
||||
logs.Println("[IP_LIBRARY]" + err.Error())
|
||||
}
|
||||
}
|
||||
}()
|
||||
})
|
||||
}
|
||||
|
||||
// 单次任务
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
teaconst "github.com/TeaOSLab/EdgeAPI/internal/const"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/events"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/goman"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/remotelogs"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/setup"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/utils"
|
||||
@@ -29,6 +30,8 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"sort"
|
||||
"strconv"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -118,10 +121,14 @@ func (this *APINode) Start() {
|
||||
_ = utils.SetRLimit(1024 * 1024)
|
||||
|
||||
// 状态变更计时器
|
||||
go NewNodeStatusExecutor().Listen()
|
||||
goman.New(func() {
|
||||
NewNodeStatusExecutor().Listen()
|
||||
})
|
||||
|
||||
// 访问日志存储管理器
|
||||
go accesslogs.SharedStorageManager.Start()
|
||||
goman.New(func() {
|
||||
accesslogs.SharedStorageManager.Start()
|
||||
})
|
||||
|
||||
// 监听RPC服务
|
||||
remotelogs.Println("API_NODE", "starting RPC server ...")
|
||||
@@ -355,13 +362,13 @@ func (this *APINode) listenPorts(apiNode *models.APINode) (isListening bool) {
|
||||
}
|
||||
remotelogs.Println("API_NODE", "retry listening port ':"+port+"' only ok")
|
||||
}
|
||||
go func() {
|
||||
goman.New(func() {
|
||||
err := this.listenRPC(listener, nil)
|
||||
if err != nil {
|
||||
remotelogs.Error("API_NODE", "listening '"+addr+"' rpc: "+err.Error())
|
||||
return
|
||||
}
|
||||
}()
|
||||
})
|
||||
isListening = true
|
||||
}
|
||||
}
|
||||
@@ -402,7 +409,7 @@ func (this *APINode) listenPorts(apiNode *models.APINode) (isListening bool) {
|
||||
}
|
||||
remotelogs.Println("API_NODE", "retry listening port ':"+port+"' only ok")
|
||||
}
|
||||
go func() {
|
||||
goman.New(func() {
|
||||
err := this.listenRPC(listener, &tls.Config{
|
||||
Certificates: certs,
|
||||
})
|
||||
@@ -410,7 +417,7 @@ func (this *APINode) listenPorts(apiNode *models.APINode) (isListening bool) {
|
||||
remotelogs.Error("API_NODE", "listening '"+addr+"' rpc: "+err.Error())
|
||||
return
|
||||
}
|
||||
}()
|
||||
})
|
||||
isListening = true
|
||||
}
|
||||
}
|
||||
@@ -430,7 +437,7 @@ func (this *APINode) listenPorts(apiNode *models.APINode) (isListening bool) {
|
||||
remotelogs.Error("API_NODE", "listening REST 'http://"+addr+"' failed: "+err.Error())
|
||||
continue
|
||||
}
|
||||
go func() {
|
||||
goman.New(func() {
|
||||
remotelogs.Println("API_NODE", "listening REST http://"+addr+" ...")
|
||||
server := &RestServer{}
|
||||
err := server.Listen(listener)
|
||||
@@ -438,7 +445,7 @@ func (this *APINode) listenPorts(apiNode *models.APINode) (isListening bool) {
|
||||
remotelogs.Error("API_NODE", "listening REST 'http://"+addr+"' failed: "+err.Error())
|
||||
return
|
||||
}
|
||||
}()
|
||||
})
|
||||
isListening = true
|
||||
}
|
||||
}
|
||||
@@ -463,7 +470,7 @@ func (this *APINode) listenPorts(apiNode *models.APINode) (isListening bool) {
|
||||
remotelogs.Error("API_NODE", "listening REST 'https://"+addr+"' failed: "+err.Error())
|
||||
continue
|
||||
}
|
||||
go func() {
|
||||
goman.New(func() {
|
||||
remotelogs.Println("API_NODE", "listening REST https://"+addr+" ...")
|
||||
server := &RestServer{}
|
||||
|
||||
@@ -479,7 +486,7 @@ func (this *APINode) listenPorts(apiNode *models.APINode) (isListening bool) {
|
||||
remotelogs.Error("API_NODE", "listening REST 'https://"+addr+"' failed: "+err.Error())
|
||||
return
|
||||
}
|
||||
}()
|
||||
})
|
||||
isListening = true
|
||||
}
|
||||
}
|
||||
@@ -501,7 +508,7 @@ func (this *APINode) listenSock() error {
|
||||
}
|
||||
|
||||
// 启动监听
|
||||
go func() {
|
||||
goman.New(func() {
|
||||
this.sock.OnCommand(func(cmd *gosock.Command) {
|
||||
switch cmd.Code {
|
||||
case "pid":
|
||||
@@ -534,6 +541,37 @@ func (this *APINode) listenSock() error {
|
||||
"isStarting": this.isStarting,
|
||||
},
|
||||
})
|
||||
case "goman":
|
||||
var posMap = map[string]maps.Map{} // file#line => Map
|
||||
for _, instance := range goman.List() {
|
||||
var pos = instance.File + "#" + types.String(instance.Line)
|
||||
m, ok := posMap[pos]
|
||||
if ok {
|
||||
m["count"] = m["count"].(int) + 1
|
||||
} else {
|
||||
m = maps.Map{
|
||||
"pos": pos,
|
||||
"count": 1,
|
||||
}
|
||||
posMap[pos] = m
|
||||
}
|
||||
}
|
||||
|
||||
var result = []maps.Map{}
|
||||
for _, m := range posMap {
|
||||
result = append(result, m)
|
||||
}
|
||||
|
||||
sort.Slice(result, func(i, j int) bool {
|
||||
return result[i]["count"].(int) > result[j]["count"].(int)
|
||||
})
|
||||
|
||||
_ = cmd.Reply(&gosock.Command{
|
||||
Params: map[string]interface{}{
|
||||
"total": runtime.NumGoroutine(),
|
||||
"result": result,
|
||||
},
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
@@ -541,7 +579,7 @@ func (this *APINode) listenSock() error {
|
||||
if err != nil {
|
||||
logs.Println("API_NODE", err.Error())
|
||||
}
|
||||
}()
|
||||
})
|
||||
|
||||
events.On(events.EventQuit, func() {
|
||||
logs.Println("API_NODE", "quit unix sock")
|
||||
|
||||
@@ -3,6 +3,7 @@ package remotelogs
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/configs"
|
||||
teaconst "github.com/TeaOSLab/EdgeAPI/internal/const"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/goman"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/logs"
|
||||
@@ -15,14 +16,14 @@ var sharedDAO DAOInterface
|
||||
func init() {
|
||||
// 定期上传日志
|
||||
ticker := time.NewTicker(60 * time.Second)
|
||||
go func() {
|
||||
goman.New(func() {
|
||||
for range ticker.C {
|
||||
err := uploadLogs()
|
||||
if err != nil {
|
||||
logs.Println("[LOG]" + err.Error())
|
||||
}
|
||||
}
|
||||
}()
|
||||
})
|
||||
}
|
||||
|
||||
// Println 打印普通信息
|
||||
|
||||
@@ -7,6 +7,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/EdgeAPI/internal/installers"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/rpc/services"
|
||||
rpcutils "github.com/TeaOSLab/EdgeAPI/internal/rpc/utils"
|
||||
@@ -325,12 +326,12 @@ func (this *NSNodeService) InstallNSNode(ctx context.Context, req *pb.InstallNSN
|
||||
return nil, err
|
||||
}
|
||||
|
||||
go func() {
|
||||
goman.New(func() {
|
||||
err = installers.SharedNSNodeQueue().InstallNodeProcess(req.NsNodeId, false)
|
||||
if err != nil {
|
||||
logs.Println("[RPC]install dns node:" + err.Error())
|
||||
}
|
||||
}()
|
||||
})
|
||||
|
||||
return &pb.InstallNSNodeResponse{}, nil
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/configs"
|
||||
"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"
|
||||
rpcutils "github.com/TeaOSLab/EdgeAPI/internal/rpc/utils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/messageconfigs"
|
||||
@@ -52,7 +53,7 @@ func NextCommandRequestId() int64 {
|
||||
func init() {
|
||||
dbs.OnReadyDone(func() {
|
||||
// 清理WaitingChannelMap
|
||||
go func() {
|
||||
goman.New(func() {
|
||||
ticker := time.NewTicker(30 * time.Second)
|
||||
for range ticker.C {
|
||||
nodeLocker.Lock()
|
||||
@@ -64,10 +65,10 @@ func init() {
|
||||
}
|
||||
nodeLocker.Unlock()
|
||||
}
|
||||
}()
|
||||
})
|
||||
|
||||
// 自动同步连接到本API节点的NS节点任务
|
||||
go func() {
|
||||
goman.New(func() {
|
||||
defer func() {
|
||||
_ = recover()
|
||||
}()
|
||||
@@ -97,7 +98,7 @@ func init() {
|
||||
}
|
||||
nodeLocker.Unlock()
|
||||
}
|
||||
}()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@@ -177,7 +178,7 @@ func (this *NSNodeService) NsNodeStream(server pb.NSNodeService_NsNodeStreamServ
|
||||
}()
|
||||
|
||||
// 发送请求
|
||||
go func() {
|
||||
goman.New(func() {
|
||||
for {
|
||||
select {
|
||||
case <-server.Context().Done():
|
||||
@@ -203,7 +204,7 @@ func (this *NSNodeService) NsNodeStream(server pb.NSNodeService_NsNodeStreamServ
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
})
|
||||
|
||||
// 接受请求
|
||||
for {
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/dnsclients"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/dnsclients/dnstypes"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
||||
"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"
|
||||
@@ -53,7 +54,7 @@ func (this *DNSDomainService) CreateDNSDomain(ctx context.Context, req *pb.Creat
|
||||
}
|
||||
|
||||
// 更新数据,且不提示错误
|
||||
go func() {
|
||||
goman.New(func() {
|
||||
domainName := req.Name
|
||||
|
||||
providerInterface := dnsclients.FindProvider(provider.Type)
|
||||
@@ -90,7 +91,7 @@ func (this *DNSDomainService) CreateDNSDomain(ctx context.Context, req *pb.Creat
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}()
|
||||
})
|
||||
|
||||
return &pb.CreateDNSDomainResponse{DnsDomainId: domainId}, nil
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models/dns"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/dnsclients/dnstypes"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/goman"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/installers"
|
||||
rpcutils "github.com/TeaOSLab/EdgeAPI/internal/rpc/utils"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/utils"
|
||||
@@ -723,12 +724,12 @@ func (this *NodeService) InstallNode(ctx context.Context, req *pb.InstallNodeReq
|
||||
return nil, err
|
||||
}
|
||||
|
||||
go func() {
|
||||
goman.New(func() {
|
||||
err = installers.SharedNodeQueue().InstallNodeProcess(req.NodeId, false)
|
||||
if err != nil {
|
||||
logs.Println("[RPC]install node:" + err.Error())
|
||||
}
|
||||
}()
|
||||
})
|
||||
|
||||
return &pb.InstallNodeResponse{}, nil
|
||||
}
|
||||
@@ -763,12 +764,12 @@ func (this *NodeService) UpgradeNode(ctx context.Context, req *pb.UpgradeNodeReq
|
||||
return nil, err
|
||||
}
|
||||
|
||||
go func() {
|
||||
goman.New(func() {
|
||||
err = installers.SharedNodeQueue().InstallNodeProcess(req.NodeId, true)
|
||||
if err != nil {
|
||||
logs.Println("[RPC]install node:" + err.Error())
|
||||
}
|
||||
}()
|
||||
})
|
||||
|
||||
return &pb.UpgradeNodeResponse{}, nil
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/configs"
|
||||
"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"
|
||||
rpcutils "github.com/TeaOSLab/EdgeAPI/internal/rpc/utils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/messageconfigs"
|
||||
@@ -54,7 +55,7 @@ func NextCommandRequestId() int64 {
|
||||
func init() {
|
||||
// 清理WaitingChannelMap
|
||||
ticker := time.NewTicker(30 * time.Second)
|
||||
go func() {
|
||||
goman.New(func() {
|
||||
for range ticker.C {
|
||||
nodeLocker.Lock()
|
||||
for requestId, request := range nodeResponseChanMap {
|
||||
@@ -65,7 +66,7 @@ func init() {
|
||||
}
|
||||
nodeLocker.Unlock()
|
||||
}
|
||||
}()
|
||||
})
|
||||
}
|
||||
|
||||
// NodeStream 节点stream
|
||||
@@ -173,7 +174,7 @@ func (this *NodeService) NodeStream(server pb.NodeService_NodeStreamServer) erro
|
||||
}()
|
||||
|
||||
// 发送请求
|
||||
go func() {
|
||||
goman.New(func() {
|
||||
for {
|
||||
select {
|
||||
case <-server.Context().Done():
|
||||
@@ -199,7 +200,7 @@ func (this *NodeService) NodeStream(server pb.NodeService_NodeStreamServer) erro
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
})
|
||||
|
||||
// 接受请求
|
||||
for {
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
teaconst "github.com/TeaOSLab/EdgeAPI/internal/const"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models/stats"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/goman"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/remotelogs"
|
||||
"github.com/iwind/TeaGo/Tea"
|
||||
"github.com/iwind/TeaGo/dbs"
|
||||
@@ -40,7 +41,7 @@ func init() {
|
||||
|
||||
dbs.OnReadyDone(func() {
|
||||
// 导入统计数据
|
||||
go func() {
|
||||
goman.New(func() {
|
||||
var duration = 30 * time.Minute
|
||||
if Tea.IsTesting() {
|
||||
// 测试条件下缩短时间,以便进行观察
|
||||
@@ -53,7 +54,7 @@ func init() {
|
||||
remotelogs.Error("SERVER_SERVICE", err.Error())
|
||||
}
|
||||
}
|
||||
}()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -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