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
No related tags found
No related merge requests found
......@@ -54,6 +54,7 @@ func init() {
<script type="module">
try {
let died = false;
let counter = 0;
let socket
let url = ""
......@@ -79,6 +80,11 @@ func init() {
socket = new WebSocket(url)
socket.onopen = function (e) {
if (died===true ){
window.location.reload();
}
console.log("[conan] Connection established");
counter = 0
};
......@@ -97,12 +103,13 @@ func init() {
console.log("[conan] Connection closed cleanly, code=" + event?.code + " reason=" + event?.reason + "");
} else {
console.error("[conan] Connection died");
died = true
setTimeout(connectWebsocket, 3000*counter)
}
};
socket.onerror = function (error) {
console.error("[conan] " + error?.message);
console.error("[conan] error", error);
};
}
......
......@@ -116,8 +116,6 @@ func executeWatchAction(watchPath string) {
r, err := result.String()
logging.LogDebug("%s", r)
websocket.SendReloadMessage()
if err != nil {
logging.LogError("watching: execute watch action error: %v", err.Error())
continue
......@@ -201,9 +199,13 @@ func InitWatch() {
})
}
watchList = append(watchList, configuration.Watch{
Path: path.Join(configuration.GetConfigurationPath(), constants.ConfigFileName),
})
c := 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 {
scanPath(w.Path)
......
......@@ -6,6 +6,8 @@ import (
"gitlab.schukai.com/oss/utilities/conan/logging"
"log"
"net/http"
"sync"
"time"
)
var (
......@@ -14,7 +16,7 @@ var (
)
func SendMessageToAll(message []byte) {
logging.LogInfo("sending message to all")
for _, conn := range connections {
conn.WriteMessage(websocket.TextMessage, message)
}
......@@ -30,8 +32,35 @@ func closeConnection(session string) error {
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"))
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 {
......@@ -49,7 +78,6 @@ func GetWebsocketHandler() http.Handler {
conn.SetCloseHandler(func(code int, text string) error {
return closeConnection(session)
})
connections[session] = conn
......
......@@ -7,6 +7,9 @@
</head>
<body>
<h1>Hello ...ddd</h1>
<div id="app"></div>
</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