Add quote template dry-run wrapper checkpoint

This commit is contained in:
2026-05-05 18:56:21 +10:00
parent 868632bd21
commit 5993826b79
2 changed files with 52 additions and 9 deletions
+27 -6
View File
@@ -9,8 +9,10 @@ set -euo pipefail
# --since 'YYYY-MM-DD HH:MM:SS'
# --hours 48
#
# This wrapper intentionally skips dry-run and calls --apply. The apply script
# still refuses duplicate applies unless --force is explicitly passed through.
# By default this wrapper applies unapplied parsed responses. Use --dry-run to
# run the poll and preview each pending apply without writing to ServiceM8.
# The apply script still refuses duplicate applies unless --force is explicitly
# passed through.
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
POLL_SCRIPT="$SCRIPT_DIR/poll_form_responses_since.py"
@@ -22,20 +24,25 @@ QUOTE_TEMPLATE_FORM_UUID="${SERVICEM8_QUOTE_TEMPLATE_FORM_UUID:-3621b6be-1d19-47
SINCE=""
HOURS="24"
FORCE="0"
DRY_RUN="0"
usage() {
cat <<EOF
Usage: $0 [--since 'YYYY-MM-DD HH:MM:SS'] [--hours N] [--force]
Usage: $0 [--since 'YYYY-MM-DD HH:MM:SS'] [--hours N] [--dry-run] [--force]
Examples:
$0
$0 --hours 48
$0 --since '2026-05-04 08:00:00'
$0 --dry-run --hours 48
This will:
1. Poll /formresponse.json using timestamp gt SINCE
2. Store/parse Quote Template responses into $DB_PATH
3. Apply parsed responses that do not already have generated materials recorded
With --dry-run, step 3 previews the ServiceM8 jobMaterial payloads only; it does
not write to ServiceM8 or mark responses as applied.
EOF
}
@@ -53,6 +60,10 @@ while [[ $# -gt 0 ]]; do
FORCE="1"
shift
;;
--dry-run)
DRY_RUN="1"
shift
;;
-h|--help)
usage
exit 0
@@ -78,6 +89,7 @@ exec > >(tee -a "$LOG_FILE") 2>&1
echo "== ServiceM8 Quote Template poll/apply run =="
echo "Started: $(date --iso-8601=seconds)"
echo "Since: $SINCE"
echo "Mode: $([[ "$DRY_RUN" == "1" ]] && echo "dry-run" || echo "apply")"
echo "DB: $DB_PATH"
echo "Log: $LOG_FILE"
echo
@@ -121,15 +133,24 @@ printf 'Found %d unapplied Quote Template response(s):\n' "${#FORM_RESPONSE_UUID
printf ' - %s\n' "${FORM_RESPONSE_UUIDS[@]}"
echo
echo "== Applying to ServiceM8 =="
APPLY_ARGS=(--apply --pretty)
if [[ "$DRY_RUN" == "1" ]]; then
echo "== Dry-run preview only; no ServiceM8 writes =="
APPLY_ARGS=(--pretty)
else
echo "== Applying to ServiceM8 =="
APPLY_ARGS=(--apply --pretty)
fi
if [[ "$FORCE" == "1" ]]; then
APPLY_ARGS+=(--force)
fi
for uuid in "${FORM_RESPONSE_UUIDS[@]}"; do
echo
echo "-- Applying form_response_uuid=$uuid --"
if [[ "$DRY_RUN" == "1" ]]; then
echo "-- Dry-run form_response_uuid=$uuid --"
else
echo "-- Applying form_response_uuid=$uuid --"
fi
"$APPLY_SCRIPT" --uuid "$uuid" "${APPLY_ARGS[@]}"
done