优化代码/增加edge-api goman命令

This commit is contained in:
GoEdgeLab
2021-12-14 10:49:29 +08:00
parent 0646d474a9
commit 515ead530d
54 changed files with 383 additions and 131 deletions

View File

@@ -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
}

View File

@@ -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 {

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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 {

View File

@@ -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())
}
}
}()
})
})
}