Support signal handling in drush process queue command

Created on 15 October 2017, almost 8 years ago
Updated 27 August 2025, 2 days ago

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.

✨ Feature request
Status

Closed: outdated

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States nvahalik

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    Afaics we do this correctly now in 8.x-1.x - see

        if (extension_loaded('pcntl')) {
          pcntl_async_signals(TRUE);
    
          pcntl_signal(SIGTERM, function () {
            $this->processor->stop();
          });
    
          pcntl_signal(SIGINT, function () {
            $this->processor->stop();
          });
        }
    

    Closing as outdated as 7.x-1.x is no longer supported.

Production build 0.71.5 2024