sync-mirror: surface tracker SELECT/INSERT failures to ops log
Some checks are pending
CI / lint-and-test (push) Waiting to run
Some checks are pending
CI / lint-and-test (push) Waiting to run
Per Ganymede review: silent fall-through with no log entry is the failure mode that bites. SELECT redirects stderr to $LOG, falls back to empty string on failure. INSERT wrapped in if-not branch with WARN log naming the (branch, sha, pr_number) so duplicate auto-create possibility is visible. Matches the Step 0/0b/4.5 observability pattern from prior reviews. Behavior unchanged on the success path; failures now greppable.
This commit is contained in:
parent
ad1d82f5ee
commit
87f97eb4fa
1 changed files with 9 additions and 2 deletions
|
|
@ -230,7 +230,9 @@ sync_github_to_forgejo_with_prs() {
|
||||||
BRANCH_SHA=$(git rev-parse "refs/remotes/origin/$branch" 2>/dev/null || true)
|
BRANCH_SHA=$(git rev-parse "refs/remotes/origin/$branch" 2>/dev/null || true)
|
||||||
fi
|
fi
|
||||||
if [ -n "$BRANCH_SHA" ]; then
|
if [ -n "$BRANCH_SHA" ]; then
|
||||||
TRACKED_PR=$(sqlite3 "$PIPELINE_DB" "SELECT pr_number FROM sync_autocreate_tracker WHERE branch=$(printf "'%s'" "${branch//\'/\'\'}") AND sha=$(printf "'%s'" "$BRANCH_SHA") LIMIT 1;" 2>/dev/null || true)
|
# stderr → $LOG so sustained sqlite3 contention surfaces in ops logs
|
||||||
|
# rather than silently falling through to a redundant auto-create.
|
||||||
|
TRACKED_PR=$(sqlite3 "$PIPELINE_DB" "SELECT pr_number FROM sync_autocreate_tracker WHERE branch=$(printf "'%s'" "${branch//\'/\'\'}") AND sha=$(printf "'%s'" "$BRANCH_SHA") LIMIT 1;" 2>>"$LOG" || echo "")
|
||||||
if [ -n "$TRACKED_PR" ]; then
|
if [ -n "$TRACKED_PR" ]; then
|
||||||
log "Skip auto-create: $branch SHA $BRANCH_SHA already tracked (PR #$TRACKED_PR)"
|
log "Skip auto-create: $branch SHA $BRANCH_SHA already tracked (PR #$TRACKED_PR)"
|
||||||
continue
|
continue
|
||||||
|
|
@ -310,8 +312,13 @@ print('no')
|
||||||
# Record (branch, sha, pr_number) so the tracker gate above can short-
|
# Record (branch, sha, pr_number) so the tracker gate above can short-
|
||||||
# circuit the next time we see this exact (branch, sha) combination.
|
# circuit the next time we see this exact (branch, sha) combination.
|
||||||
# INSERT OR IGNORE: idempotent if a concurrent run already inserted.
|
# INSERT OR IGNORE: idempotent if a concurrent run already inserted.
|
||||||
|
# WARN log on failure: silent INSERT failure under sustained sqlite3
|
||||||
|
# contention would mask the loop reappearing on the next cycle (HAS_PR
|
||||||
|
# only saves us while the closed PR is in the 50-item pagination window).
|
||||||
if [ -n "$BRANCH_SHA" ] && [[ "$PR_NUM" =~ ^[0-9]+$ ]]; then
|
if [ -n "$BRANCH_SHA" ] && [[ "$PR_NUM" =~ ^[0-9]+$ ]]; then
|
||||||
sqlite3 "$PIPELINE_DB" "INSERT OR IGNORE INTO sync_autocreate_tracker (branch, sha, pr_number) VALUES ($(printf "'%s'" "${branch//\'/\'\'}"), $(printf "'%s'" "$BRANCH_SHA"), $PR_NUM);" 2>/dev/null || true
|
if ! sqlite3 "$PIPELINE_DB" "INSERT OR IGNORE INTO sync_autocreate_tracker (branch, sha, pr_number) VALUES ($(printf "'%s'" "${branch//\'/\'\'}"), $(printf "'%s'" "$BRANCH_SHA"), $PR_NUM);" 2>>"$LOG"; then
|
||||||
|
log "WARN: tracker insert failed for $branch SHA $BRANCH_SHA (PR #$PR_NUM) — duplicate auto-create possible next cycle"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Step 4.5: Link GitHub PR to Forgejo PR in pipeline DB
|
# Step 4.5: Link GitHub PR to Forgejo PR in pipeline DB
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue