71 lines
1.5 KiB
Go
71 lines
1.5 KiB
Go
package task
|
|
|
|
import (
|
|
"bufio"
|
|
"context"
|
|
"log/slog"
|
|
"os/exec"
|
|
"sync"
|
|
|
|
"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"
|
|
)
|
|
|
|
type HealthCheckData struct {
|
|
Command types.FFmpegCommand `json:"command"`
|
|
}
|
|
|
|
func RunHealthCheck(conf config.Config, t *types.Task, data HealthCheckData) {
|
|
ctx := context.TODO()
|
|
l := log.GetTaskLogger(t)
|
|
l.InfoContext(ctx, "Running ffmpeg", "command", data.Command)
|
|
cmd := exec.CommandContext(ctx, conf.Worker.FFmpegPath, data.Command.GetArgs()...)
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
stdout, err := cmd.StdoutPipe()
|
|
if err != nil {
|
|
l.ErrorContext(ctx, "Error getting StdoutPipe", "err", err)
|
|
return
|
|
}
|
|
|
|
wg.Add(1)
|
|
outScanner := bufio.NewScanner(stdout)
|
|
go func() {
|
|
for outScanner.Scan() {
|
|
slog.InfoContext(ctx, outScanner.Text(), "pipe", "out")
|
|
}
|
|
wg.Done()
|
|
}()
|
|
|
|
stderr, err := cmd.StderrPipe()
|
|
if err != nil {
|
|
l.ErrorContext(ctx, "Error getting StderrPipe", "err", err)
|
|
return
|
|
}
|
|
wg.Add(1)
|
|
errScanner := bufio.NewScanner(stderr)
|
|
go func() {
|
|
for errScanner.Scan() {
|
|
slog.InfoContext(ctx, errScanner.Text(), "pipe", "err")
|
|
}
|
|
wg.Done()
|
|
}()
|
|
|
|
err = cmd.Start()
|
|
if err != nil {
|
|
l.ErrorContext(ctx, "Error Starting ffmpeg", "err", err)
|
|
return
|
|
}
|
|
|
|
wg.Wait()
|
|
|
|
err = cmd.Wait()
|
|
if err != nil {
|
|
l.ErrorContext(ctx, "Error Running ffmpeg", "err", err)
|
|
return
|
|
}
|
|
t.Status = constants.TASK_STATUS_SUCCESS
|
|
}
|