Add Worker Cleanup
This commit is contained in:
parent
5dbd15c71c
commit
4194ab5944
2 changed files with 27 additions and 0 deletions
|
@ -40,6 +40,9 @@ func Start(_conf config.Config) {
|
||||||
serverClose <- true
|
serverClose <- true
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
stopCleanup := make(chan bool, 1)
|
||||||
|
go cleanupDeadWorkers(stopCleanup)
|
||||||
|
|
||||||
sigs := make(chan os.Signal, 1)
|
sigs := make(chan os.Signal, 1)
|
||||||
signal.Notify(sigs, os.Interrupt)
|
signal.Notify(sigs, os.Interrupt)
|
||||||
select {
|
select {
|
||||||
|
@ -50,6 +53,7 @@ func Start(_conf config.Config) {
|
||||||
stopCtx, cancel := context.WithTimeout(context.Background(), time.Second*10)
|
stopCtx, cancel := context.WithTimeout(context.Background(), time.Second*10)
|
||||||
server.Shutdown(stopCtx)
|
server.Shutdown(stopCtx)
|
||||||
cancel()
|
cancel()
|
||||||
|
stopCleanup <- true
|
||||||
slog.Info("Done")
|
slog.Info("Done")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,3 +101,26 @@ func readMessage(ctx context.Context, c *websocket.Conn) error {
|
||||||
slog.InfoContext(ctx, "Got Websocket Message", "type", t.String(), "data", data)
|
slog.InfoContext(ctx, "Got Websocket Message", "type", t.String(), "data", data)
|
||||||
return c.Write(ctx, t, data)
|
return c.Write(ctx, t, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func cleanupDeadWorkers(stop chan bool) {
|
||||||
|
ticker := time.NewTicker(time.Second)
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-ticker.C:
|
||||||
|
func() {
|
||||||
|
WorkersMutex.Lock()
|
||||||
|
defer WorkersMutex.Unlock()
|
||||||
|
|
||||||
|
for uuid, w := range Workers {
|
||||||
|
if !w.Connected && w.ConnectionChanged.Add(time.Minute*5).Before(time.Now()) {
|
||||||
|
slog.Warn("Removing Dead Worker", "uuid", uuid, "name", w.Name)
|
||||||
|
delete(Workers, uuid)
|
||||||
|
// TODO Free any Jobs that the Worker had
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
case <-stop:
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue