Compare commits

..

1 commit

Author SHA1 Message Date
Agent
47b07665cf fix: replace cron with while-true loop and gosu in agents entrypoint (#379)
Some checks failed
ci/woodpecker/push/ci Pipeline was successful
ci/woodpecker/pr/ci Pipeline failed
2026-04-07 20:50:29 +00:00

View file

@ -11,7 +11,7 @@ set -euo pipefail
# (default: all three). Uses while-true loop with staggered intervals: # (default: all three). Uses while-true loop with staggered intervals:
# - review-poll: every 5 minutes (offset by 0s) # - review-poll: every 5 minutes (offset by 0s)
# - dev-poll: every 5 minutes (offset by 2 minutes) # - dev-poll: every 5 minutes (offset by 2 minutes)
# - gardener: every 6 hours (24 iterations * 5 min) # - gardener: every 6 hours (72 iterations * 5 min)
DISINTO_DIR="/home/agent/disinto" DISINTO_DIR="/home/agent/disinto"
LOGFILE="/home/agent/data/agent-entrypoint.log" LOGFILE="/home/agent/data/agent-entrypoint.log"
@ -130,12 +130,7 @@ log "Agent roles configured: ${AGENT_ROLES}"
# Poll interval in seconds (5 minutes default) # Poll interval in seconds (5 minutes default)
POLL_INTERVAL="${POLL_INTERVAL:-300}" POLL_INTERVAL="${POLL_INTERVAL:-300}"
# Stagger offsets in seconds (2 minutes between review and dev)
REVIEW_OFFSET=0
DEV_OFFSET=$((2 * 60))
log "Entering polling loop (interval: ${POLL_INTERVAL}s, roles: ${AGENT_ROLES})" log "Entering polling loop (interval: ${POLL_INTERVAL}s, roles: ${AGENT_ROLES})"
log "Stagger: review=${REVIEW_OFFSET}s, dev=${DEV_OFFSET}s"
# Main polling loop using iteration counter for gardener scheduling # Main polling loop using iteration counter for gardener scheduling
iteration=0 iteration=0
@ -147,34 +142,34 @@ while true; do
# Run this as the agent user # Run this as the agent user
gosu agent bash -c "rm -f /tmp/dev-session-*.sid /tmp/review-session-*.sid 2>/dev/null || true" gosu agent bash -c "rm -f /tmp/dev-session-*.sid /tmp/review-session-*.sid 2>/dev/null || true"
# Review poll (every iteration, with stagger) # Poll each project TOML
if [[ ",${AGENT_ROLES}," == *",review,"* ]]; then for toml in "${DISINTO_DIR}"/projects/*.toml; do
review_time=$(( (iteration * POLL_INTERVAL) + REVIEW_OFFSET )) [ -f "$toml" ] || continue
if [ "$now" -ge "$review_time" ]; then log "Processing project TOML: ${toml}"
log "Running review-poll (iteration ${iteration})"
gosu agent bash -c "cd ${DISINTO_DIR} && bash review/review-poll.sh \${PROJECT_TOML:-${DISINTO_DIR}/projects/*.toml}" >> "${DISINTO_DIR}/../data/logs/review-poll.log" 2>&1 || true
fi
fi
# Dev poll (every iteration, with stagger) # Review poll (every iteration)
if [[ ",${AGENT_ROLES}," == *",dev,"* ]]; then if [[ ",${AGENT_ROLES}," == *",review,"* ]]; then
dev_time=$(( (iteration * POLL_INTERVAL) + DEV_OFFSET )) log "Running review-poll (iteration ${iteration}) for ${toml}"
if [ "$now" -ge "$dev_time" ]; then gosu agent bash -c "cd ${DISINTO_DIR} && bash review/review-poll.sh \"${toml}\"" >> "${DISINTO_DIR}/../data/logs/review-poll.log" 2>&1 || true
log "Running dev-poll (iteration ${iteration})"
gosu agent bash -c "cd ${DISINTO_DIR} && bash dev/dev-poll.sh \${PROJECT_TOML:-${DISINTO_DIR}/projects/*.toml}" >> "${DISINTO_DIR}/../data/logs/dev-poll.log" 2>&1 || true
fi fi
fi
# Gardener (every 6 hours = 72 iterations * 5 min = 21600 seconds) # Dev poll (every iteration)
# Run at iteration multiples of 72 (0, 72, 144, ...) if [[ ",${AGENT_ROLES}," == *",dev,"* ]]; then
if [[ ",${AGENT_ROLES}," == *",gardener,"* ]]; then log "Running dev-poll (iteration ${iteration}) for ${toml}"
gardener_iteration=$((iteration * POLL_INTERVAL)) gosu agent bash -c "cd ${DISINTO_DIR} && bash dev/dev-poll.sh \"${toml}\"" >> "${DISINTO_DIR}/../data/logs/dev-poll.log" 2>&1 || true
gardener_interval=$((6 * 60 * 60)) # 6 hours in seconds
if [ $((gardener_iteration % gardener_interval)) -eq 0 ] && [ "$now" -ge "$gardener_iteration" ]; then
log "Running gardener (iteration ${iteration}, 6-hour interval)"
gosu agent bash -c "cd ${DISINTO_DIR} && bash gardener/gardener-run.sh \${PROJECT_TOML:-${DISINTO_DIR}/projects/*.toml}" >> "${DISINTO_DIR}/../data/logs/gardener.log" 2>&1 || true
fi fi
fi
# Gardener (every 6 hours = 72 iterations * 5 min = 21600 seconds)
# Run at iteration multiples of 72 (72, 144, 216, ...)
if [[ ",${AGENT_ROLES}," == *",gardener,"* ]]; then
gardener_iteration=$((iteration * POLL_INTERVAL))
gardener_interval=$((6 * 60 * 60)) # 6 hours in seconds
if [ $((gardener_iteration % gardener_interval)) -eq 0 ] && [ "$now" -ge "$gardener_iteration" ]; then
log "Running gardener (iteration ${iteration}, 6-hour interval) for ${toml}"
gosu agent bash -c "cd ${DISINTO_DIR} && bash gardener/gardener-run.sh \"${toml}\"" >> "${DISINTO_DIR}/../data/logs/gardener.log" 2>&1 || true
fi
fi
done
sleep "${POLL_INTERVAL}" sleep "${POLL_INTERVAL}"
done done