From 5b827a6148a5cbe40523536a8739af1e28048233 Mon Sep 17 00:00:00 2001 From: Roman Buryan Date: Wed, 14 Oct 2026 15:02:09 +0300 Subject: [PATCH] =?UTF-8?q?fix(F6-4):=20=D0=B7=D0=B0=D0=BF=D0=B8=D1=81?= =?UTF-8?q?=D1=8C=20=D1=80=D0=B5=D0=B7=D1=83=D0=BB=D1=8C=D1=82=D0=B0=D1=82?= =?UTF-8?q?=D0=B0=20=D0=B2=20=D0=BE=D1=87=D0=B5=D1=80=D0=B5=D0=B4=D1=8C,?= =?UTF-8?q?=20=D0=B5=D0=B4=D0=B8=D0=BD=D1=8B=D0=B9=20=D0=B6=D1=83=D1=80?= =?UTF-8?q?=D0=BD=D0=B0=D0=BB=20=D1=80=D0=B0=D0=BD=D0=BD=D0=B5=D1=80=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ops/update-manager/update-runner.sh | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/ops/update-manager/update-runner.sh b/ops/update-manager/update-runner.sh index a9e47fd..47eed65 100755 --- a/ops/update-manager/update-runner.sh +++ b/ops/update-manager/update-runner.sh @@ -46,8 +46,13 @@ q() { # $1 = SQL, печатает результат psql -h "$PG_HOST" -U "$PG_USER" -d "$PG_DB" -tAc "$1" 2>>"$LOG_FILE" } -q_set() { # $1 = значение результата, $2 = SQL с :'res' - psql -h "$PG_HOST" -U "$PG_USER" -d "$PG_DB" -v res="$1" -tAc "$2" 2>>"$LOG_FILE" +q_finish() { # $1 = id задачи, $2 = итоговый статус, $3 = текст результата + # Подстановка :'res' не работает при одиночном запросе (-c), поэтому + # текст экранируется вручную и подставляется прямо в строку. + local txt="${3//\'/\'\'}" + psql -h "$PG_HOST" -U "$PG_USER" -d "$PG_DB" -tAc \ + "UPDATE update_queue SET status='$2', finished_at=now(), result='$txt' WHERE id=$1" \ + 2>>"$LOG_FILE" } resolve_service() { @@ -104,8 +109,7 @@ q "UPDATE update_queue SET status='running', started_at=now(), attempts=attempts # Уведомления приходят с именем контейнера — переводим в имя сервиса реестра TARGET=$(resolve_service "$service") if [ -z "$TARGET" ]; then - q_set "сервис '$service' не найден в реестре $SERVICES_FILE" \ - "UPDATE update_queue SET status='failed', finished_at=now(), result=:'res' WHERE id=$id" >/dev/null + q_finish "$id" failed "сервис '$service' не найден в реестре обновлений" notify "🚨 Обновление $service: сервис не найден в реестре обновлений. Добавьте его в services.yaml." log "не удалось сопоставить '$service' с реестром" exit 1 @@ -116,8 +120,7 @@ if [ "$TARGET" != "$service" ]; then fi if [ ! -x "$SAFE_UPDATE" ]; then - q_set "не найден safe-update.sh" \ - "UPDATE update_queue SET status='failed', finished_at=now(), result=:'res' WHERE id=$id" >/dev/null + q_finish "$id" failed "не найден safe-update.sh" notify "🚨 Обновление $service не запущено: не найден safe-update.sh" log "нет $SAFE_UPDATE" exit 1 @@ -129,12 +132,12 @@ rc=$? if [ "$rc" -eq 0 ]; then res=$(echo "$out" | tail -3 | tr '\n' ' ') - q_set "$res" "UPDATE update_queue SET status='done', finished_at=now(), result=:'res' WHERE id=$id" >/dev/null + q_finish "$id" done "$res" log "задача $id выполнена" notify "✅ $service обновлён до $newver" else res=$(echo "$out" | tail -6 | tr '\n' ' ') - q_set "$res" "UPDATE update_queue SET status='failed', finished_at=now(), result=:'res' WHERE id=$id" >/dev/null + q_finish "$id" failed "$res" log "задача $id провалена" notify "🚨 $service — обновление не удалось, выполняется откат. Журнал: $LOG_FILE" fi