From b99a818040b8812e5df644bda356464b5e98ce36 Mon Sep 17 00:00:00 2001 From: Samuel Lorch Date: Sat, 6 Jul 2024 03:05:58 +0200 Subject: [PATCH] Cleanup old temp files on startup --- task/healthcheck.go | 2 +- task/transcode.go | 4 ++-- worker/worker.go | 15 +++++++++++++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/task/healthcheck.go b/task/healthcheck.go index a8ab6a2..9039634 100644 --- a/task/healthcheck.go +++ b/task/healthcheck.go @@ -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 { diff --git a/task/transcode.go b/task/transcode.go index 3a1e863..9d6a143 100644 --- a/task/transcode.go +++ b/task/transcode.go @@ -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 { diff --git a/worker/worker.go b/worker/worker.go index 07dbad6..411c872 100644 --- a/worker/worker.go +++ b/worker/worker.go @@ -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