Closed danielbachhuber closed 11 years ago
Check how many workers are needed to complete the jobs available in the queue. There should be a wp-cli command to calculate this.
I am not sure if the workers count should be calculated based off job queue size, we are better to find how many workers the system can handle and spawn up to that many. As a worker will quit once there are no jobs to do, there isn't much overhead in doing that.
This is what I have so far, it will spawn 1 worker in the background if one is not currently running
#!/bin/bash
RUN_JOBS="wp job-agency find-work"
# check how how many jobs we need to do
JOBS=`wp job-agency check-employment-needs`
# check how many workers are working
RUNNING=$(((`ps aux | grep 'job-agency find-work' | wc -l`)-1))
echo "Jobs to do: "$JOBS
echo "Workers: "$RUNNING
if [ $JOBS -gt '0' -a $RUNNING -eq 0 ]
then eval ${RUN_JOBS} &
##then echo $JOBS
fi
Our bash script will manage how many workers we have available. When run by system cron, it should:
Simple and easy.