prevent completed download restart

This commit is contained in:
2024-07-02 11:37:06 +02:00
parent 98f0ea3bd2
commit 3edebbdb6c
4 changed files with 34 additions and 20 deletions

View File

@@ -2,7 +2,6 @@ package rpc
import (
"io"
"log"
"net/http"
"github.com/gorilla/websocket"
@@ -30,8 +29,6 @@ func WebSocket(w http.ResponseWriter, r *http.Request) {
for {
mtype, reader, err := c.NextReader()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
log.Println(err)
break
}
@@ -40,7 +37,6 @@ func WebSocket(w http.ResponseWriter, r *http.Request) {
writer, err := c.NextWriter(mtype)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
log.Println(err)
break
}

View File

@@ -121,8 +121,11 @@ func (s *Service) KillAll(args NoArgs, killed *string) error {
s.logger.Info("Killing all spawned processes")
var (
keys = s.db.Keys()
err error
keys = s.db.Keys()
removeFunc = func(p *internal.Process) error {
defer s.db.Delete(p.Id)
return p.Kill()
}
)
for _, key := range *keys {
@@ -131,22 +134,24 @@ func (s *Service) KillAll(args NoArgs, killed *string) error {
return err
}
if proc != nil {
err := proc.Kill()
if err != nil {
s.logger.Info(
"failed killing process",
slog.String("id", proc.Id),
slog.String("err", err.Error()),
)
return err
}
s.logger.Info("succesfully killed process", slog.String("id", proc.Id))
if proc == nil {
s.db.Delete(key)
continue
}
if err := removeFunc(proc); err != nil {
s.logger.Info(
"failed killing process",
slog.String("id", proc.Id),
slog.Any("err", err),
)
continue
}
s.logger.Info("succesfully killed process", slog.String("id", proc.Id))
}
return err
return nil
}
// Remove a process from the db rendering it unusable if active