sync_audio_bulk.sh: lote de sincronizacion de audio TTS con parada en primer fallo #215
@@ -57,15 +57,28 @@ if [ -n "$ids_csv" ]; then
|
|||||||
elif [ -n "$ids_file" ]; then
|
elif [ -n "$ids_file" ]; then
|
||||||
mapfile -t ids < "$ids_file"
|
mapfile -t ids < "$ids_file"
|
||||||
elif [ -n "$carta" ]; then
|
elif [ -n "$carta" ]; then
|
||||||
mapfile -t ids < <(
|
# No usar `mapfile < <(cmd)`: la sustitución de procesos no deja comprobar
|
||||||
python3 - "$carta" <<'PYEOF'
|
# de forma fiable el exit code de `cmd` (mapfile ve su propio $?, no el de
|
||||||
import subprocess, sys
|
# la tubería). Si la consulta falla, un array vacío se confundiría con
|
||||||
sys.path.insert(0, "scripts")
|
# "la carta no tiene artículos" y el lote saldría "éxito" sin sincronizar
|
||||||
|
# nada. Se resuelve a fichero temporal y se comprueba el rc de python
|
||||||
|
# explícitamente antes de poblar el array.
|
||||||
|
carta_tmpfile="$(mktemp)"
|
||||||
|
python3 - "$carta" "$SCRIPT_DIR" > "$carta_tmpfile" <<'PYEOF'
|
||||||
|
import sys
|
||||||
|
sys.path.insert(0, sys.argv[2])
|
||||||
from sync_audio_to_prod import carta_article_ids
|
from sync_audio_to_prod import carta_article_ids
|
||||||
for pid in carta_article_ids(int(sys.argv[1])):
|
for pid in carta_article_ids(int(sys.argv[1])):
|
||||||
print(pid)
|
print(pid)
|
||||||
PYEOF
|
PYEOF
|
||||||
)
|
py_rc=$?
|
||||||
|
if [ $py_rc -ne 0 ]; then
|
||||||
|
echo "ERROR: fallo consultando la cola de la carta $carta (exit $py_rc), no se sincroniza nada." >&2
|
||||||
|
rm -f "$carta_tmpfile"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
mapfile -t ids < "$carta_tmpfile"
|
||||||
|
rm -f "$carta_tmpfile"
|
||||||
else
|
else
|
||||||
usage
|
usage
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -86,6 +86,8 @@ def carta_article_ids(carta_id: int) -> list[int]:
|
|||||||
DB_NAME, "-N", "-e", q],
|
DB_NAME, "-N", "-e", q],
|
||||||
capture_output=True, text=True, timeout=60,
|
capture_output=True, text=True, timeout=60,
|
||||||
)
|
)
|
||||||
|
if r.returncode != 0:
|
||||||
|
raise RuntimeError(f"consulta de _carta_id={carta_id} falló (rc={r.returncode}): {r.stderr.strip()[:300]}")
|
||||||
return [int(x) for x in r.stdout.split() if x.isdigit()]
|
return [int(x) for x in r.stdout.split() if x.isdigit()]
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user