mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-12-08 06:00:24 +08:00
实现HTTP部分功能
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
"time"
|
||||
)
|
||||
|
||||
// 检查变更的集群列表
|
||||
type ChangedClustersAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
@@ -14,22 +16,50 @@ func (this *ChangedClustersAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *ChangedClustersAction) RunGet(params struct{}) {
|
||||
resp, err := this.RPC().NodeClusterRPC().FindAllChangedNodeClusters(this.AdminContext(), &pb.FindAllChangedNodeClustersRequest{})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
func (this *ChangedClustersAction) RunGet(params struct {
|
||||
IsNotifying bool
|
||||
}) {
|
||||
timeout := time.NewTimer(55 * time.Second) // 比客户端提前结束,避免在客户端产生一个请求错误
|
||||
|
||||
result := []maps.Map{}
|
||||
for _, cluster := range resp.Clusters {
|
||||
result = append(result, maps.Map{
|
||||
"id": cluster.Id,
|
||||
"name": cluster.Name,
|
||||
})
|
||||
}
|
||||
this.Data["clusters"] = []interface{}{}
|
||||
|
||||
this.Data["clusters"] = result
|
||||
Loop:
|
||||
for {
|
||||
select {
|
||||
case <-this.Request.Context().Done():
|
||||
break Loop
|
||||
case <-timeout.C:
|
||||
break Loop
|
||||
default:
|
||||
// 继续
|
||||
}
|
||||
|
||||
resp, err := this.RPC().NodeClusterRPC().FindAllChangedNodeClusters(this.AdminContext(), &pb.FindAllChangedNodeClustersRequest{})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
result := []maps.Map{}
|
||||
for _, cluster := range resp.Clusters {
|
||||
result = append(result, maps.Map{
|
||||
"id": cluster.Id,
|
||||
"name": cluster.Name,
|
||||
})
|
||||
}
|
||||
|
||||
// 从提醒到提醒消失
|
||||
if len(result) == 0 && params.IsNotifying {
|
||||
break
|
||||
}
|
||||
|
||||
this.Data["clusters"] = result
|
||||
if len(result) > 0 {
|
||||
break
|
||||
}
|
||||
|
||||
time.Sleep(1 * time.Second)
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user