init
This commit is contained in:
1 parent
48eaf48797
commit
e32e55df15
20 files changed
+369
-117
No files matched your search
@@ -0,0 +1,23 @@
|
||||
package subs
|
||||
|
||||
import "isp-config-service/ws"
|
||||
|
||||
func (h *socketEventHandler) handleModuleReady(conn ws.Conn, data []byte) {
|
||||
|
||||
}
|
||||
|
||||
func (h *socketEventHandler) handleRoutesUpdate(conn ws.Conn, data []byte) {
|
||||
|
||||
}
|
||||
|
||||
func (h *socketEventHandler) handleModuleRequirements(conn ws.Conn, data []byte) {
|
||||
|
||||
}
|
||||
|
||||
func (h *socketEventHandler) handleConfigSchema(conn ws.Conn, data []byte) {
|
||||
|
||||
}
|
||||
|
||||
func (h *socketEventHandler) handleRequestConfig(conn ws.Conn, data []byte) {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package subs
|
||||
|
||||
import (
|
||||
"isp-config-service/ws"
|
||||
)
|
||||
|
||||
func (h *socketEventHandler) applyCommandOnLeader(conn ws.Conn, cmd []byte) string {
|
||||
_, err := h.cluster.SyncApplyOnLeader(cmd)
|
||||
if err != nil {
|
||||
return err.Error()
|
||||
}
|
||||
return ok
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package subs
|
||||
|
||||
import (
|
||||
"github.com/integration-system/isp-lib/logger"
|
||||
"isp-config-service/cluster"
|
||||
"isp-config-service/holder"
|
||||
"isp-config-service/state"
|
||||
"isp-config-service/ws"
|
||||
)
|
||||
|
||||
const (
|
||||
ok = "ok"
|
||||
|
||||
followersRoom = "followers"
|
||||
)
|
||||
|
||||
type socketEventHandler struct {
|
||||
socket *ws.WebsocketServer
|
||||
cluster *cluster.ClusterClient
|
||||
state *state.Store
|
||||
}
|
||||
|
||||
func (h *socketEventHandler) SubscribeAll() {
|
||||
h.socket.
|
||||
OnConnect(h.handleConnect).
|
||||
OnDisconnect(h.handleDisconnect).
|
||||
OnError(h.handleError).
|
||||
OnWithAck(cluster.ApplyCommandEvent, h.applyCommandOnLeader)
|
||||
}
|
||||
|
||||
func (h *socketEventHandler) handleConnect(conn ws.Conn) {
|
||||
if conn.IsConfigClusterNode() {
|
||||
holder.Socket.Rooms().Join(conn, followersRoom)
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func (h *socketEventHandler) handleDisconnect(conn ws.Conn) {
|
||||
if conn.IsConfigClusterNode() {
|
||||
holder.Socket.Rooms().Leave(conn, followersRoom)
|
||||
}
|
||||
}
|
||||
|
||||
func (h *socketEventHandler) handleError(conn ws.Conn, err error) {
|
||||
logger.Warnf("socket.io: %v", err)
|
||||
}
|
||||
|
||||
func NewSocketEventHandler(socket *ws.WebsocketServer, cluster *cluster.ClusterClient, state *state.Store) *socketEventHandler {
|
||||
return &socketEventHandler{
|
||||
socket: socket,
|
||||
cluster: cluster,
|
||||
state: state,
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user