Add Worker Cleanup
This commit is contained in:
parent
5dbd15c71c
commit
4194ab5944
2 changed files with 27 additions and 0 deletions
|
@ -101,3 +101,26 @@ func readMessage(ctx context.Context, c *websocket.Conn) error {
|
|||
slog.InfoContext(ctx, "Got Websocket Message", "type", t.String(), "data", 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
Add a link
Reference in a new issue