allez on essaie ca

This commit is contained in:
Gaël
2025-09-08 18:53:34 +02:00
parent a1e462eab9
commit 542aea6602
2 changed files with 41 additions and 11 deletions

View File

@@ -566,6 +566,7 @@ async def run_weekly():
# -------------------- Scheduler -------------------- # -------------------- Scheduler --------------------
async def run_forever_sunday_noon(): async def run_forever_sunday_noon():
logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s")
"""Run at next Sunday 12:00 Europe/Brussels, then every 7 days.""" """Run at next Sunday 12:00 Europe/Brussels, then every 7 days."""
while True: while True:
now = datetime.now(TZ) now = datetime.now(TZ)

View File

@@ -1,29 +1,58 @@
#!/bin/sh #!/bin/sh
set -eu set -eu
# Arrêt propre: en sh, on utilise INT/TERM (sans "SIG") log() { printf '%s %s\n' "[$(date -u +%FT%TZ)]" "$*"; }
stop() { stop() {
echo "[stop] shutting down..." log "stopping..."
# Tuer proprement les 2 enfants si présents
[ -n "${PID1-}" ] && kill -TERM "$PID1" 2>/dev/null || true [ -n "${PID1-}" ] && kill -TERM "$PID1" 2>/dev/null || true
[ -n "${PID2-}" ] && kill -TERM "$PID2" 2>/dev/null || true [ -n "${PID2-}" ] && kill -TERM "$PID2" 2>/dev/null || true
[ -n "${TPID-}" ] && kill -TERM "$TPID" 2>/dev/null || true
wait || true wait || true
exit 0 exit 0
} }
trap stop INT TERM trap stop INT TERM
# (facultatif si tu fais un git pull ici) cd /app
# git fetch --all || true export GIT_TERMINAL_PROMPT=0
# git reset --hard origin/main || true
# Lancer les 2 bots en arrière-plan # MAJ forcée du code à chaque (re)démarrage
python -u post_rss_to_ghost.py & PID1=$! if [ -d .git ]; then
python -u presquegratos.py & PID2=$! i=0
while [ $i -lt 5 ]; do
if git fetch --all --prune && git reset --hard origin/main; then
log "git updated to origin/main"
break
fi
i=$((i+1))
log "git update failed (attempt $i/5); retrying in 10s..."
sleep 10
done
[ $i -ge 5 ] && log "WARNING: git update failed after 5 attempts — continuing with current code"
else
log "WARNING: /app is not a git repo; skipping git update"
fi
# Attendre qu'un des deux termine; l'autre sera tué dans stop() # Dossiers logs
# /bin/sh na pas toujours wait -n, on fait un petit poll mkdir -p /var/log
: > /var/log/daily.log
: > /var/log/weekly.log
# Lancer les 2 bots (logs non bufferisés)
python -u post_rss_to_ghost.py > /var/log/daily.log 2>&1 & PID1=$!
python -u presquegratos.py > /var/log/weekly.log 2>&1 & PID2=$!
# Suivre les 2 fichiers de logs dans la sortie du conteneur
tail -F /var/log/daily.log /var/log/weekly.log &
TPID=$!
# Attente portable (pas de wait -n en /bin/sh)
while :; do while :; do
if ! kill -0 "$PID1" 2>/dev/null; then wait "$PID1" || true; break; fi if ! kill -0 "$PID1" 2>/dev/null; then wait "$PID1" || true; break; fi
if ! kill -0 "$PID2" 2>/dev/null; then wait "$PID2" || true; break; fi if ! kill -0 "$PID2" 2>/dev/null; then wait "$PID2" || true; break; fi
sleep 1 sleep 1
done done
# Si un des scripts sort, on arrête le tail (le trap TERM arrêtera l'autre script)
kill -TERM "$TPID" 2>/dev/null || true
wait || true