I've been doing a lot of stuff with queues and one of the biggest challenges I have are trying to keep hung entries out of the queues and being able to ensure that my queues are able to interact with their "worker managers."
Background:
I'm running on Acquia's stack and they provide the screen
command to me. So with screen
I use another shell script to run the scripts... this script is called forever
function forever () {
COMMAND=$@
EXIT_STATUS="255"
while true; do
$COMMAND;
EXIT_STATUS=$?
if [ "$EXIT_STATUS" -eq "131" ]; then
echo "Command $COMMAND exited successfully."
break;
elif [ "$EXIT_STATUS" -eq "130" ]; then
echo "Command $COMMAND restarting gracefully."
sleep 1
else
echo "Command '$@' crashed with exit code $EXIT_STATUS. Respawning..." >&2
sleep 1
fi
done
}
Anyway, one of the key things is that just sending the SIGTERM
doesn't give me any assurance that the operation will end well. To this end, adding proper signal handling would allow for all of the following operations:
1. Sending SIGINT
would cause the script to finish the current item and then exit gracefully with the , signifying that the job just needs to restart. Useful for code or configuration updates to live-running operations.
2. Sending SIGQUIT
tells the script to finish completely, and then quit without being restarted. This, of course, is dependent upon the worker manager.
3. Sending SIGSTOP
tells the processor to stop working items but not to quit or restart. It will simply become idle and draw little to no CPU.
4. Sending SIGCONT
tells the processor to start working items again.
Of course, if your version of PHP doesn't have these items, then they shouldn't be exposed.