mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-12-05 16:50:34 +08:00
Websocket信息变更时通知更新
This commit is contained in:
@@ -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 {
|
||||||
|
|||||||
@@ -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)
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -47,12 +47,15 @@ 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()
|
||||||
return err
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return this.NotifyUpdate(tx, websocketId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找启用中的条目
|
// 查找启用中的条目
|
||||||
@@ -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)
|
||||||
return err
|
if err != nil {
|
||||||
|
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
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user