Skip to content
Snippets Groups Projects
Verified Commit d0ec8b66 authored by Volker Schukai's avatar Volker Schukai :alien:
Browse files

chore: commit save point

parent 726fc1e0
No related branches found
Tags v1.13.2
No related merge requests found
...@@ -54,6 +54,7 @@ func init() { ...@@ -54,6 +54,7 @@ func init() {
<script type="module"> <script type="module">
try { try {
let died = false;
let counter = 0; let counter = 0;
let socket let socket
let url = "" let url = ""
...@@ -79,6 +80,11 @@ func init() { ...@@ -79,6 +80,11 @@ func init() {
socket = new WebSocket(url) socket = new WebSocket(url)
socket.onopen = function (e) { socket.onopen = function (e) {
if (died===true ){
window.location.reload();
}
console.log("[conan] Connection established"); console.log("[conan] Connection established");
counter = 0 counter = 0
}; };
...@@ -97,12 +103,13 @@ func init() { ...@@ -97,12 +103,13 @@ func init() {
console.log("[conan] Connection closed cleanly, code=" + event?.code + " reason=" + event?.reason + ""); console.log("[conan] Connection closed cleanly, code=" + event?.code + " reason=" + event?.reason + "");
} else { } else {
console.error("[conan] Connection died"); console.error("[conan] Connection died");
died = true
setTimeout(connectWebsocket, 3000*counter) setTimeout(connectWebsocket, 3000*counter)
} }
}; };
socket.onerror = function (error) { socket.onerror = function (error) {
console.error("[conan] " + error?.message); console.error("[conan] error", error);
}; };
} }
......
...@@ -116,8 +116,6 @@ func executeWatchAction(watchPath string) { ...@@ -116,8 +116,6 @@ func executeWatchAction(watchPath string) {
r, err := result.String() r, err := result.String()
logging.LogDebug("%s", r) logging.LogDebug("%s", r)
websocket.SendReloadMessage()
if err != nil { if err != nil {
logging.LogError("watching: execute watch action error: %v", err.Error()) logging.LogError("watching: execute watch action error: %v", err.Error())
continue continue
...@@ -201,9 +199,13 @@ func InitWatch() { ...@@ -201,9 +199,13 @@ func InitWatch() {
}) })
} }
watchList = append(watchList, configuration.Watch{ c := path.Join(configuration.GetConfigurationPath(), constants.ConfigFileName)
Path: path.Join(configuration.GetConfigurationPath(), constants.ConfigFileName),
}) if _, err := os.Stat(c); err == nil {
watchList = append(watchList, configuration.Watch{
Path: path.Join(configuration.GetConfigurationPath(), constants.ConfigFileName),
})
}
for _, w := range watchList { for _, w := range watchList {
scanPath(w.Path) scanPath(w.Path)
......
...@@ -6,6 +6,8 @@ import ( ...@@ -6,6 +6,8 @@ import (
"gitlab.schukai.com/oss/utilities/conan/logging" "gitlab.schukai.com/oss/utilities/conan/logging"
"log" "log"
"net/http" "net/http"
"sync"
"time"
) )
var ( var (
...@@ -14,7 +16,7 @@ var ( ...@@ -14,7 +16,7 @@ var (
) )
func SendMessageToAll(message []byte) { func SendMessageToAll(message []byte) {
logging.LogInfo("sending message to all")
for _, conn := range connections { for _, conn := range connections {
conn.WriteMessage(websocket.TextMessage, message) conn.WriteMessage(websocket.TextMessage, message)
} }
...@@ -30,8 +32,35 @@ func closeConnection(session string) error { ...@@ -30,8 +32,35 @@ func closeConnection(session string) error {
return nil return nil
} }
func SendReloadMessage() { var timerMutex *sync.Mutex
var waitForReload bool
func init() {
timerMutex = &sync.Mutex{}
waitForReload = false
}
func doReload() {
timerMutex.Lock()
defer timerMutex.Unlock()
SendMessageToAll([]byte("reload")) SendMessageToAll([]byte("reload"))
waitForReload = false
}
func SendReloadMessage() {
timerMutex.Lock()
defer timerMutex.Unlock()
if waitForReload {
return
}
time.AfterFunc(time.Second*2, doReload)
logging.LogInfo("timer ...")
waitForReload = true
} }
func GetWebsocketHandler() http.Handler { func GetWebsocketHandler() http.Handler {
...@@ -49,7 +78,6 @@ func GetWebsocketHandler() http.Handler { ...@@ -49,7 +78,6 @@ func GetWebsocketHandler() http.Handler {
conn.SetCloseHandler(func(code int, text string) error { conn.SetCloseHandler(func(code int, text string) error {
return closeConnection(session) return closeConnection(session)
}) })
connections[session] = conn connections[session] = conn
......
...@@ -7,6 +7,9 @@ ...@@ -7,6 +7,9 @@
</head> </head>
<body> <body>
<h1>Hello ...ddd</h1> <h1>Hello ...ddd</h1>
<div id="app"></div> <div id="app"></div>
</body> </body>
1
1
1
1
{"version":"0.1.19"} {"version":"0.1.29"}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment