#!/bin/bash
# Runs a memory-heavy command, one at a time across every agent: this machine has 8 GB of RAM.
# Usage: bin/heavy .venv/bin/python scripts/something.py --args
LOCK=/tmp/leis-heavy.lock
until mkdir "$LOCK" 2>/dev/null; do
  if [ -f "$LOCK/pid" ] && ! kill -0 "$(cat "$LOCK/pid")" 2>/dev/null; then
    rm -rf "$LOCK"
    continue
  fi
  sleep 20
done
echo $$ > "$LOCK/pid"
trap 'rm -rf "$LOCK"' EXIT
nice -n 10 "$@"
