refactor: Integrate shared clean_start into ingest preparation
This commit is contained in:
parent
e0a39d8a15
commit
31340f9d19
3 changed files with 19 additions and 13 deletions
|
|
@ -42,20 +42,25 @@ case "$cmd" in
|
||||||
esac
|
esac
|
||||||
|
|
||||||
logger -t n8n-pi-wrap "ok: pi ingest ${genome} ${raw_path}"
|
logger -t n8n-pi-wrap "ok: pi ingest ${genome} ${raw_path}"
|
||||||
|
|
||||||
|
# Per-genome lock: serialize writes; never two concurrent ingests on the same genome.
|
||||||
|
exec 9>"/run/lock/kg-ingest-${genome}.lock" 2>/dev/null || exec 9>"/tmp/kg-ingest-${genome}.lock"
|
||||||
|
if ! flock -n 9; then
|
||||||
|
echo '{"status":"busy","reason":"another ingest is running for this genome","genome":"'"$genome"'"}'
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
set -a; . "${HOME}/.config/knowledge-genome.env"; set +a
|
set -a; . "${HOME}/.config/knowledge-genome.env"; set +a
|
||||||
cd "${GENOMES_ROOT}/${genome}" || { echo '{"status":"error","reason":"unknown genome"}'; exit 1; }
|
cd "${GENOMES_ROOT}/${genome}" || { echo '{"status":"error","reason":"unknown genome"}'; exit 1; }
|
||||||
|
|
||||||
# The raw file must actually exist under the genome's raw/ dir.
|
# The raw file must actually exist under the genome's raw/ dir.
|
||||||
[ -f "$raw_path" ] || { echo '{"status":"error","reason":"raw file not found"}'; exit 1; }
|
[ -f "$raw_path" ] || { echo '{"status":"error","reason":"raw file not found"}'; exit 1; }
|
||||||
|
|
||||||
# Clean start on the configured base (develop), pinned to the remote. Destroys only
|
# Clean start on the configured base (single source of truth in lib/clean-start.sh).
|
||||||
# vm101's scratch checkout (never a shared branch, never a force-push) — this is by design.
|
: "${KG_LIB_DIR:=${HOME}/knowledge-genome-orchestrator/lib}"
|
||||||
# `clean -fd` also removes leftover UNTRACKED files (e.g. wiki/sources/* or a stale
|
source "${KG_LIB_DIR}/clean-start.sh" 2>/dev/null \
|
||||||
# .ingest-manifest.json from a half-finished previous run) that `reset --hard` won't touch.
|
|| { echo '{"status":"error","reason":"clean-start.sh not found"}'; exit 1; }
|
||||||
git fetch -q origin \
|
clean_start || { echo '{"status":"error","reason":"clean-start failed"}'; exit 1; }
|
||||||
&& git switch -q "${INGEST_BASE:-main}" 2>/dev/null \
|
|
||||||
&& git reset -q --hard "origin/${INGEST_BASE:-main}" \
|
|
||||||
&& git clean -q -fd
|
|
||||||
|
|
||||||
# SEMANTIC step: dedicated script drives pi to WRITE wiki pages + manifest.
|
# SEMANTIC step: dedicated script drives pi to WRITE wiki pages + manifest.
|
||||||
# (NOT `pi -p "/skill:ingest ..."`, which makes the model reply in chat and write nothing.)
|
# (NOT `pi -p "/skill:ingest ..."`, which makes the model reply in chat and write nothing.)
|
||||||
|
|
|
||||||
|
|
@ -12,11 +12,11 @@ genome="${1:?usage: pending-raw.sh <genome>}"
|
||||||
base_dir="${GENOMES_ROOT:-${HOME}/genomes}"
|
base_dir="${GENOMES_ROOT:-${HOME}/genomes}"
|
||||||
cd "${base_dir}/${genome}" 2>/dev/null || { echo '{"status":"error","reason":"unknown genome"}'; exit 1; }
|
cd "${base_dir}/${genome}" 2>/dev/null || { echo '{"status":"error","reason":"unknown genome"}'; exit 1; }
|
||||||
|
|
||||||
# Clean start on the configured base (Step 3 will extract this to lib/clean-start.sh).
|
# Clean start on the configured base (single source of truth in lib/clean-start.sh).
|
||||||
git fetch -q origin \
|
: "${KG_LIB_DIR:=${HOME}/knowledge-genome-orchestrator/lib}"
|
||||||
&& git switch -q "${INGEST_BASE:-main}" 2>/dev/null \
|
source "${KG_LIB_DIR}/clean-start.sh" 2>/dev/null \
|
||||||
&& git reset -q --hard "origin/${INGEST_BASE:-main}" \
|
|| { echo '{"status":"error","reason":"clean-start.sh not found"}'; exit 1; }
|
||||||
&& git clean -q -fd
|
clean_start || { echo '{"status":"error","reason":"clean-start failed"}'; exit 1; }
|
||||||
|
|
||||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
SLUG="${SCRIPT_DIR}/slug.sh"
|
SLUG="${SCRIPT_DIR}/slug.sh"
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ setup() {
|
||||||
export PENDING="${SKILL_SCRIPTS}/pending-raw.sh"
|
export PENDING="${SKILL_SCRIPTS}/pending-raw.sh"
|
||||||
export GENOMES_ROOT="${BATS_TEST_TMPDIR}"
|
export GENOMES_ROOT="${BATS_TEST_TMPDIR}"
|
||||||
export INGEST_BASE="main"
|
export INGEST_BASE="main"
|
||||||
|
export KG_LIB_DIR="${LIB_DIR}"
|
||||||
|
|
||||||
g_src="$(make_fixture_genome)"
|
g_src="$(make_fixture_genome)"
|
||||||
export g_name="fixture-genome"
|
export g_name="fixture-genome"
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue