Cleanup old temp files on startup

This commit is contained in:
Samuel Lorch 2024-07-06 03:05:58 +02:00
parent e8f7521fa4
commit b99a818040
3 changed files with 18 additions and 3 deletions

View file

@ -17,7 +17,7 @@ func RunHealthCheck(conf config.Config, t *types.Task, data types.HealthCheckDat
l := log.GetTaskLogger(t)
// TODO Figure out how to get correct file ending
path := filepath.Join(conf.Worker.TempDir, fmt.Sprintf("%v-%v.mkv", t.ID, t.FileID))
path := filepath.Join(conf.Worker.TempDir, fmt.Sprintf("morffix-health-%v-%v.mkv", t.ID, t.FileID))
// Set ffmpeg input path
if len(t.FfmpegCommand.InputFiles) == 0 {

View file

@ -17,8 +17,8 @@ func RunTranscode(conf config.Config, t *types.Task, data types.TranscodeData) {
l := log.GetTaskLogger(t)
// TODO Figure out how to get correct file ending
src_path := filepath.Join(conf.Worker.TempDir, fmt.Sprintf("src-%v-%v.mkv", t.ID, t.FileID))
dst_path := filepath.Join(conf.Worker.TempDir, fmt.Sprintf("dst-%v-%v.mkv", t.ID, t.FileID))
src_path := filepath.Join(conf.Worker.TempDir, fmt.Sprintf("morffix-src-%v-%v.mkv", t.ID, t.FileID))
dst_path := filepath.Join(conf.Worker.TempDir, fmt.Sprintf("morffix-dst-%v-%v.mkv", t.ID, t.FileID))
// Set ffmpeg input path
if len(t.FfmpegCommand.InputFiles) == 0 {

View file

@ -5,6 +5,7 @@ import (
"io"
"log/slog"
"net/http"
"path/filepath"
"git.lastassault.de/speatzle/morffix/rpc"
@ -36,6 +37,20 @@ func Start(_conf config.Config) {
return
}
slog.InfoContext(ctx, "Cleaning tmp Files...")
files, err := filepath.Glob("/tmp/morffix-*")
if err != nil {
slog.Error("Get tmp Files", "err", err)
return
}
for _, f := range files {
slog.InfoContext(ctx, "Deleting File", "path", f)
if err := os.Remove(f); err != nil {
slog.Error("Deleting tmp File", "err", err, "path", f)
return
}
}
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, os.Interrupt)
exit := false