Compare commits

..

1 commit

Author SHA1 Message Date
Agent
c4e0ea66dd fix: replace cron with while-true loop and gosu in agents entrypoint (#379)
All checks were successful
ci/woodpecker/push/ci Pipeline was successful
ci/woodpecker/pr/ci Pipeline was successful
2026-04-07 20:38:11 +00:00

View file

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