mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2026-09-29 04:28:06 -05:00
feat(scrape): add scrape-lock-status diagnostic for archive-root lock
Introduce read-only scrape-lock-status.sh and surface lock state during operator-handoff so shared Documents archives show active or stale holders before starting another scrape.
This commit is contained in:
@@ -65,5 +65,9 @@ if [[ "$channel_status" -ne 0 ]] || ! grep -q 'Handoff complete' <<<"$channel_ou
|
||||
printf '%s\n' "$channel_output" >&2
|
||||
exit 1
|
||||
fi
|
||||
if ! grep -q 'Scrape lock status' <<<"$handoff_output"; then
|
||||
printf 'operator-handoff missing scrape lock status section\n' >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf 'operator-handoff-smoke: ok\n'
|
||||
|
||||
94
scripts/tests/scrape-lock-status-smoke.sh
Executable file
94
scripts/tests/scrape-lock-status-smoke.sh
Executable file
@@ -0,0 +1,94 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -Eeuo pipefail
|
||||
|
||||
REPO_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd -P)
|
||||
STATUS="$REPO_ROOT/scripts/scrape-lock-status.sh"
|
||||
TMP_DIR=$(mktemp -d "${TMPDIR:-/tmp}/dce-lock-status-smoke.XXXXXX")
|
||||
ARCHIVE_ROOT="$TMP_DIR/archive"
|
||||
CONFIG_PATH="$TMP_DIR/config.json"
|
||||
LOCK_FILE="$ARCHIVE_ROOT/.dce-scrape.lock"
|
||||
HOLDER_PID=""
|
||||
|
||||
cleanup() {
|
||||
if [[ -n "$HOLDER_PID" ]] && kill -0 "$HOLDER_PID" 2>/dev/null; then
|
||||
kill "$HOLDER_PID" 2>/dev/null || true
|
||||
wait "$HOLDER_PID" 2>/dev/null || true
|
||||
fi
|
||||
rm -rf "$TMP_DIR"
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
command -v flock >/dev/null 2>&1 || {
|
||||
echo "SKIP: flock not available"
|
||||
exit 0
|
||||
}
|
||||
|
||||
mkdir -p "$ARCHIVE_ROOT"
|
||||
cat >"$CONFIG_PATH" <<JSON
|
||||
{
|
||||
"archive_root": "$ARCHIVE_ROOT",
|
||||
"targets": []
|
||||
}
|
||||
JSON
|
||||
|
||||
chmod +x "$STATUS"
|
||||
|
||||
set +e
|
||||
free_output=$("$STATUS" --config "$CONFIG_PATH" 2>&1)
|
||||
free_status=$?
|
||||
set -e
|
||||
|
||||
if [[ "$free_status" -ne 0 ]] || ! grep -q 'state: free (no lock file)' <<<"$free_output"; then
|
||||
echo "expected free lock status" >&2
|
||||
printf '%s\n' "$free_output" >&2
|
||||
exit 1
|
||||
fi
|
||||
if ! grep -Fq "$LOCK_FILE" <<<"$free_output"; then
|
||||
echo "expected archive-root lock path in output" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
(
|
||||
exec {lock_fd}>>"$LOCK_FILE"
|
||||
flock -n "$lock_fd" || exit 1
|
||||
printf 'pid=%s\nstarted=2020-01-01T00:00:00Z\ncmd=lock-status-smoke-holder\n' "$$" >"${LOCK_FILE}.meta"
|
||||
sleep 120
|
||||
) &
|
||||
HOLDER_PID=$!
|
||||
sleep 0.2
|
||||
|
||||
set +e
|
||||
held_output=$("$STATUS" --config "$CONFIG_PATH" 2>&1)
|
||||
held_status=$?
|
||||
set -e
|
||||
|
||||
if [[ "$held_status" -ne 1 ]] || ! grep -q 'state: held (active scrape)' <<<"$held_output"; then
|
||||
echo "expected held lock status exit 1" >&2
|
||||
printf '%s\n' "$held_output" >&2
|
||||
exit 1
|
||||
fi
|
||||
if ! grep -q 'lock-status-smoke-holder' <<<"$held_output"; then
|
||||
echo "expected holder cmd in status output" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
kill "$HOLDER_PID" 2>/dev/null || true
|
||||
wait "$HOLDER_PID" 2>/dev/null || true
|
||||
HOLDER_PID=""
|
||||
|
||||
printf 'pid=99999999\nstarted=2020-01-01T00:00:00Z\ncmd=dead-smoke-holder\n' >"${LOCK_FILE}.meta"
|
||||
touch "$LOCK_FILE"
|
||||
|
||||
set +e
|
||||
stale_output=$("$STATUS" --config "$CONFIG_PATH" 2>&1)
|
||||
stale_status=$?
|
||||
set -e
|
||||
|
||||
if [[ "$stale_status" -ne 0 ]] || ! grep -q 'state: stale (reclaimable' <<<"$stale_output"; then
|
||||
echo "expected stale reclaimable status after holder exit" >&2
|
||||
printf '%s\n' "$stale_output" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf 'scrape-lock-status-smoke: ok\n'
|
||||
Reference in New Issue
Block a user