mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-12 11:20:27 +08:00
实现缓存策略的部分功能
This commit is contained in:
55
internal/web/actions/default/servers/components/cache/testWrite.go
vendored
Normal file
55
internal/web/actions/default/servers/components/cache/testWrite.go
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
package cache
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/nodes/nodeutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/messageconfigs"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
)
|
||||
|
||||
type TestWriteAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *TestWriteAction) RunPost(params struct {
|
||||
ClusterId int64
|
||||
CachePolicyId int64
|
||||
Key string
|
||||
Value string
|
||||
}) {
|
||||
cachePolicyResp, err := this.RPC().HTTPCachePolicyRPC().FindEnabledHTTPCachePolicyConfig(this.AdminContext(), &pb.FindEnabledHTTPCachePolicyConfigRequest{CachePolicyId: params.CachePolicyId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
cachePolicyJSON := cachePolicyResp.CachePolicyJSON
|
||||
if len(cachePolicyJSON) == 0 {
|
||||
this.Fail("找不到要操作的缓存策略")
|
||||
}
|
||||
|
||||
// 发送命令
|
||||
msg := &messageconfigs.WriteCacheMessage{
|
||||
CachePolicyJSON: cachePolicyJSON,
|
||||
Key: params.Key,
|
||||
Value: []byte(params.Value),
|
||||
LifeSeconds: 3600,
|
||||
}
|
||||
results, err := nodeutils.SendMessageToCluster(this.AdminContext(), params.ClusterId, messageconfigs.MessageCodeWriteCache, msg, 10)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
isAllOk := true
|
||||
for _, result := range results {
|
||||
if !result.IsOK {
|
||||
isAllOk = false
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
this.Data["isAllOk"] = isAllOk
|
||||
this.Data["results"] = results
|
||||
|
||||
this.Success()
|
||||
}
|
||||
Reference in New Issue
Block a user