2 ms·
Let's say you have a cronjob YOUR_CRONJOB.php that is slow that uses a query to get the data it needs to iterate over. Change your sql where to have MOD(id, t
by ransom1538 4y ago
Let's say you have a cronjob YOUR_CRONJOB.php that is slow that uses a query to get the data it needs to iterate over. Change your sql where to have MOD(id, total_threads) = MOD. Toss this into jenkins and you are set.
This will fork it and wait until it ends.
#!/bin/bash
TOTAL=`ps aux | grep YOUR_CRONJOB.php | grep -v grep | wc -l`
echo "TOTAL PROCESSES ALREADY RUNNING :"$TOTAL
MAX_THREADS=20
TOTAL_MODS="$(($MAX_THREADS-1))"
echo "TOTAL MODS: "$TOTAL_MODS
if [ $TOTAL -eq 0 ]
then
echo "RUNNING..."
for i in $(seq 0 $TOTAL_MODS)
do
echo "Starting thread $i"
timeout 10000 php YOUR_CRONJOB.php $i $MAX_THREADS &
pids[${i}]=$!
done
echo "FINISHED FORKING"
else
echo "NOT RUNNING...."
fi
for pid in ${pids[*]}; do
wait $pid
done
echo "OK FINISHED"