From 5ee0655e6ee14515df3887270fc9176e267d9293 Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Sun, 9 Jan 2022 20:23:05 -0700 Subject: [PATCH] Slightly smarter encode failure reporting --- scripts/common.sh | 3 +++ scripts/encoder.sh | 34 ++++++++++++++++------------------ 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/scripts/common.sh b/scripts/common.sh index f0bcaf9..5cec577 100755 --- a/scripts/common.sh +++ b/scripts/common.sh @@ -4,6 +4,9 @@ : ${OUTDIR:=/incoming} export OUTDIR +# This gets set to the directory containing what's currently running +: ${SCRIPTS:=$(dirname $0)} + log () { printf "\033[36m=== [%s] \033[0m %s\n" "$0" "$*" } diff --git a/scripts/encoder.sh b/scripts/encoder.sh index 6c35503..3e08219 100755 --- a/scripts/encoder.sh +++ b/scripts/encoder.sh @@ -2,30 +2,28 @@ . $(dirname $0)/common.sh -run_in () { - ( - cd $1; shift - setenv status "encoding" - "$@" - ) -} - while sleep 2; do echo "idle" > $OUTDIR/status.encoder for mtype in audio video; do ls $mtype | while read d; do - encode=/scripts/$mtype.encode.sh + encode=$SCRIPTS/$mtype.encode.sh workdir=$mtype/$d status=$(cd $workdir && getenv status) - [ "$status" = "read finished" ] || continue - - echo "encoding" > $OUTDIR/status.encoder - if ! run_in $workdir $encode; then - log "$encode failed" - (cd $workdir && setenv status "encode failed") - else - rm -rf $workdir - fi + case "$status" in + "encoding") + (cd $workdir && setenv status "encode interrupted") + ;; + "read finished") + echo "encoding" > $OUTDIR/status.encoder + (cd $workdir && setenv status "encoding") + if ! (cd $workdir && $encode); then + log "$encode failed" + (cd $workdir && setenv status "encode failed") + else + rm -rf $workdir + fi + ;; + esac done done done