Implement Healthcheck Command Execution
This commit is contained in:
parent
04a1bb4ccb
commit
86ba486f47
1 changed files with 61 additions and 7 deletions
|
@ -1,17 +1,71 @@
|
|||
package task
|
||||
|
||||
import "git.lastassault.de/speatzle/morffix/constants"
|
||||
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 string `json:"command"`
|
||||
Command types.FFmpegCommand `json:"command"`
|
||||
}
|
||||
|
||||
func (t *Task) RunHealthCheck(data HealthCheckData) {
|
||||
defer func() {
|
||||
if t.Status == constants.TASK_STATUS_RUNNING {
|
||||
t.Status = constants.TASK_STATUS_FAILED
|
||||
t.Log = append(t.Log, "Task Status Failed by Defer")
|
||||
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
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue