Websocket信息变更时通知更新

This commit is contained in:
GoEdgeLab
2021-01-19 13:14:25 +08:00
parent fa9dcc2f04
commit 5d021ec0b5
4 changed files with 44 additions and 13 deletions

View File

@@ -723,6 +723,16 @@ func (this *HTTPWebDAO) FindEnabledWebIdWithGzipId(tx *dbs.Tx, gzipId int64) (we
FindInt64Col(0) FindInt64Col(0)
} }
// 查找包含某个Websocket配置的Web
func (this *HTTPWebDAO) FindEnabledWebIdWithWebsocketId(tx *dbs.Tx, websocketId int64) (webId int64, err error) {
return this.Query(tx).
State(HTTPWebStateEnabled).
ResultPk().
Where("JSON_CONTAINS(websocket, :jsonQuery)").
Param("jsonQuery", maps.Map{"websocketId": websocketId}.AsJSON()).
FindInt64Col(0)
}
// 查找使用此Web的Server // 查找使用此Web的Server
func (this *HTTPWebDAO) FindWebServerId(tx *dbs.Tx, webId int64) (serverId int64, err error) { func (this *HTTPWebDAO) FindWebServerId(tx *dbs.Tx, webId int64) (serverId int64, err error) {
if webId <= 0 { if webId <= 0 {

View File

@@ -129,3 +129,15 @@ func TestHTTPWebDAO_FindEnabledWebIdWithGzip(t *testing.T) {
} }
t.Log("webId:", webId) t.Log("webId:", webId)
} }
func TestHTTPWebDAO_FindEnabledWebIdWithWebsocket(t *testing.T) {
dbs.NotifyReady()
var tx *dbs.Tx
webId, err := SharedHTTPWebDAO.FindEnabledWebIdWithWebsocketId(tx, 5)
if err != nil {
t.Fatal(err)
}
t.Log("webId:", webId)
}

View File

@@ -47,13 +47,16 @@ func (this *HTTPWebsocketDAO) EnableHTTPWebsocket(tx *dbs.Tx, id int64) error {
} }
// 禁用条目 // 禁用条目
func (this *HTTPWebsocketDAO) DisableHTTPWebsocket(tx *dbs.Tx, id int64) error { func (this *HTTPWebsocketDAO) DisableHTTPWebsocket(tx *dbs.Tx, websocketId int64) error {
_, err := this.Query(tx). _, err := this.Query(tx).
Pk(id). Pk(websocketId).
Set("state", HTTPWebsocketStateDisabled). Set("state", HTTPWebsocketStateDisabled).
Update() Update()
if err != nil {
return err return err
} }
return this.NotifyUpdate(tx, websocketId)
}
// 查找启用中的条目 // 查找启用中的条目
func (this *HTTPWebsocketDAO) FindEnabledHTTPWebsocket(tx *dbs.Tx, id int64) (*HTTPWebsocket, error) { func (this *HTTPWebsocketDAO) FindEnabledHTTPWebsocket(tx *dbs.Tx, id int64) (*HTTPWebsocket, error) {
@@ -150,5 +153,20 @@ func (this *HTTPWebsocketDAO) UpdateWebsocket(tx *dbs.Tx, websocketId int64, han
op.RequestSameOrigin = requestSameOrigin op.RequestSameOrigin = requestSameOrigin
op.RequestOrigin = requestOrigin op.RequestOrigin = requestOrigin
err := this.Save(tx, op) err := this.Save(tx, op)
if err != nil {
return err return err
} }
return this.NotifyUpdate(tx, websocketId)
}
// 通知更新
func (this *HTTPWebsocketDAO) NotifyUpdate(tx *dbs.Tx, websocketId int64) error {
webId, err := SharedHTTPWebDAO.FindEnabledWebIdWithWebsocketId(tx, websocketId)
if err != nil {
return err
}
if webId > 0 {
return SharedHTTPWebDAO.NotifyUpdate(tx, webId)
}
return nil
}

View File

@@ -15,15 +15,6 @@ func TestNodeDAO_FindAllNodeIdsMatch(t *testing.T) {
t.Log(nodeIds) t.Log(nodeIds)
} }
func TestNodeDAO_FindChangedClusterIds(t *testing.T) {
var tx *dbs.Tx
clusterIds, err := SharedNodeDAO.FindChangedClusterIds(tx)
if err != nil {
t.Fatal(err)
}
t.Log(clusterIds)
}
func TestNodeDAO_UpdateNodeUp(t *testing.T) { func TestNodeDAO_UpdateNodeUp(t *testing.T) {
dbs.NotifyReady() dbs.NotifyReady()
var tx *dbs.Tx var tx *dbs.Tx