Created
December 21, 2014 10:39
-
-
Save it-can/31059375f53719b65f4a to your computer and use it in GitHub Desktop.
FuelPHP worker script for https://bitbucket.org/codeyellow/queue. More info here: http://fuelphp.com/forums/discussion/13340/anyone-experience-with-php-resque#Item_6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Queue manager script, to make sure the required number of worker instances | |
# are running. Schedule this in cron to make sure any crashed workers will | |
# be restarted. | |
# | |
# Get the full path to ourselfs | |
SCRIPTPATH="$( dirname "$( which "$0" )" )" | |
# how many workers do we need to start? | |
if [ $# -gt 0 ]; then | |
WORKERS=$1 | |
else | |
WORKERS=1; | |
fi | |
# where does the php binary live? | |
PHP=`which php` | |
# command that starts the worker | |
COMMAND="$SCRIPTPATH/../../../oil refine queueworker" | |
# loop to process the worker instantiation | |
while : | |
do | |
# bail out if we have started enough workers | |
PROCESS_COUNT=`pgrep -f "$COMMAND" | wc -l` | |
if [ $PROCESS_COUNT -eq $WORKERS ]; then | |
exit 0 | |
fi | |
# too many workers running? | |
if [ $PROCESS_COUNT -gt $WORKERS ]; then | |
# kill a worker off nicely | |
PROCESS=`pgrep -f -n "$COMMAND"` | |
kill -15 $PROCESS | |
sleep 1 | |
else | |
# start a new worker | |
$PHP $COMMAND & | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment