morffix/task/healthcheck.go
Samuel Lorch 5ecfd81967
All checks were successful
/ release (push) Successful in 52s
preserve file extension
2025-03-19 20:59:38 +01:00

54 lines
1.3 KiB
Go

package task
import (
"context"
"fmt"
"os"
"path/filepath"
"git.lastassault.de/speatzle/morffix/config"
"git.lastassault.de/speatzle/morffix/constants"
"git.lastassault.de/speatzle/morffix/task/log"
"git.lastassault.de/speatzle/morffix/types"
)
func RunHealthCheck(conf config.Config, t *types.Task, data types.HealthCheckData) {
ctx := context.TODO()
l := log.GetTaskLogger(t)
// TODO Figure out how to get correct file ending
path := filepath.Join(conf.Worker.TempDir, fmt.Sprintf("morffix-health-%v-%v."+t.FileExtension, t.ID, t.FileID))
// Set ffmpeg input path
if len(t.FfmpegCommand.InputFiles) == 0 {
l.ErrorContext(ctx, "FFmpeg Command has no input files", "command", t.FfmpegCommand)
return
}
t.FfmpegCommand.InputFiles[0].Path = path
// TODO cleanup file when done
defer func() {
err := os.Remove(path)
if err != nil {
l.ErrorContext(ctx, "Removing File", "err", err, "path", path)
} else {
l.InfoContext(ctx, "File Removed Succesfully", "path", path)
}
}()
err := downloadFile(ctx, l, conf, path, t)
if err != nil {
l.ErrorContext(ctx, "File Download Failed", "err", err)
return
}
err = runFfmpegCommand(ctx, l, conf, t.FfmpegCommand)
if err != nil {
l.ErrorContext(ctx, "FFmpeg Failed", "err", err)
return
}
l.InfoContext(ctx, "Task Success")
t.Status = constants.TASK_STATUS_SUCCESS
}