I'm setting up a separate cron job that just calls drush p-queue-work however, I found that when there are no items in the queue, drush returns an exit code of 1 (error). This is problematic for systems which monitor the success or failure of cron runs, and it's not really an error.

Suggest returning a error code of 0 if there is nothing in the queue.

CommentFileSizeAuthor
#3 2902179-3.patch1.16 KBkim.pepper
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

kim.pepper created an issue. See original summary.

kim.pepper’s picture

Issue summary: View changes
kim.pepper’s picture

Status: Active » Needs review
FileSize
1.16 KB

Not sure what's going on there with closures and functions being called inside each other. It's quite confusing to read.

Here's my attempt at a patch.

nielsvm’s picture

Status: Needs review » Closed (outdated)

During the rewrite to Drush 9, the p:queue-work received a huge rewrite in order to work cleanly with the new Symfony\Console and SiteProcess APIs. Unfortunately, calling pqw without parameters will still fail hard and spawns a process fork!. So under Drush 9, this is what happens:

$ drush p:queue-work && echo "UNIX status = success"

In QueueCommands.php line 519:
  The queue is empty or has only locked items!

However there's good news, because the now respected --no-interaction parameter does exactly what you need:

drush p:queue-work --help
Process one or more chunks of items from the queue.

Examples:
  drush p:queue-work                             Process one chunk of queue items from the queue.
  drush p:queue-work --format=json|yaml          Process one chunk and return parsable output.
  drush p:queue-work --finish                    Keep processing until the queue is empty.
  drush p:queue-work --finish --format=json|yaml Keep processing and return parsable output.
  drush p:queue-work --no-interaction            Process one chunk without process fork. This mode suited for cron jobs and does not set a UNIX return status.

While it still reports an error on empty queues, here the UNIX status code is always negative:

$ drush p:queue-work --no-interaction --format=yaml && echo "UNIX status = success"
error: empty
total: 0
processing: 0
succeeded: 0
failed: 0
not_supported: 0

UNIX status = success

When using this, rely on your Drupal logs to detect failure.