← back to Designer Wallcoverings
auto-save: 2026-07-13T08:23:39 (4 files) — pending-approval/boost-filter-consolidation-2026-06-25 scripts/pr-contact-for-price vendor-scrapers/china-seas-refresh DW-Programming/ImportNewSkufromURL/scripts/ensure-import-app.sh
d90232b252b73dd49c3c768f6ea13362a02c4ed3 · 2026-07-13 08:23:43 -0700 · Steve Abrams
Files touched
A DW-Programming/ImportNewSkufromURL/scripts/ensure-import-app.sh
Diff
commit d90232b252b73dd49c3c768f6ea13362a02c4ed3
Author: Steve Abrams <steve@designerwallcoverings.com>
Date: Mon Jul 13 08:23:43 2026 -0700
auto-save: 2026-07-13T08:23:39 (4 files) — pending-approval/boost-filter-consolidation-2026-06-25 scripts/pr-contact-for-price vendor-scrapers/china-seas-refresh DW-Programming/ImportNewSkufromURL/scripts/ensure-import-app.sh
---
.../scripts/ensure-import-app.sh | 42 ++++++++++++++++++++++
1 file changed, 42 insertions(+)
diff --git a/DW-Programming/ImportNewSkufromURL/scripts/ensure-import-app.sh b/DW-Programming/ImportNewSkufromURL/scripts/ensure-import-app.sh
new file mode 100755
index 00000000..68fb0d0d
--- /dev/null
+++ b/DW-Programming/ImportNewSkufromURL/scripts/ensure-import-app.sh
@@ -0,0 +1,42 @@
+#!/bin/sh
+# ensure-import-app.sh — make sure the ImportNewSkufromURL app answers on :9830.
+# The one shared heal path: the drain driver AND the queue runner both call this
+# instead of each inventing its own restart logic. Idempotent — safe to call
+# every pass. Exit 0 = app answering, exit 1 = could not heal (caller decides).
+#
+# History: on 2026-07-04 the hand-launched :9830 died; 1,027 brewster queue items
+# burned all 6 retry attempts against ECONNREFUSED and went terminally failed
+# while the drain declared itself DRAINED. The app now lives under pm2
+# (autorestart) and this script is the resurrection path if pm2 itself loses it.
+APP_DIR="$(cd "$(dirname "$0")/.." && pwd)"
+PM2=${PM2_BIN:-pm2}
+NAME=ImportNewSkufromURL-9830
+URL=http://127.0.0.1:9830/
+
+alive() {
+ # any HTTP status counts as alive — we only care that the socket answers
+ code=$(curl -s -o /dev/null -w '%{http_code}' -m 5 "$URL" 2>/dev/null)
+ [ -n "$code" ] && [ "$code" != "000" ]
+}
+
+alive && exit 0
+
+echo "[ensure-import-app] :9830 dead — attempting pm2 heal $(date)"
+if $PM2 describe "$NAME" >/dev/null 2>&1; then
+ $PM2 restart "$NAME" --update-env >/dev/null 2>&1
+else
+ # DEV mode on purpose: no production build exists (.next has only dev artifacts)
+ # and the runner already tolerates dev-recompile socket drops. next binary is
+ # invoked directly — `pm2 start npm` loses the port flag through npm's arg pass.
+ cd "$APP_DIR" && $PM2 start node_modules/next/dist/bin/next --name "$NAME" -- dev -p 9830 -H 0.0.0.0 >/dev/null 2>&1
+fi
+$PM2 save >/dev/null 2>&1
+
+# Next boot + first compile can take a while — poll up to 2 minutes
+i=0
+while [ $i -lt 24 ]; do
+ alive && { echo "[ensure-import-app] :9830 healed after ${i}x5s"; exit 0; }
+ sleep 5; i=$((i+1))
+done
+echo "[ensure-import-app] FAILED to heal :9830 after 120s"
+exit 1
← 2e675372 auto-save: 2026-07-13T07:53:32 (4 files) — pending-approval/
·
back to Designer Wallcoverings
·
import drain self-heals: backend-down never burns item attem 84bb022a →