Problem/Motivation

When the Drupal cron runner is executing a queue, and if a queue worker throws a \Drupal\Core\Queue\SuspendQueueException, a RfcLogLevel::ERROR level log and backtrace are logged, and potentially recorded to a database of some kind. Throwing a SuspendQueueException exception doesnt needed to be treated so severely. For example in the normal course of business I exceed the quotas of an external API, I need to suspend the queue temporarily. This does not warrant logging an 'error' and backtrace.

Proposed resolution

Log a less severe log entry.
Dont log the exception and backtrace.

Remaining tasks

API changes

Data model changes

Original report

In the related issue you can requeue a single item back to the queue.
There already is functionality to suspend the whole queue by throwing a SuspendQueueException. Downside of this is that a watchdog is written. In my case this is not needed. I just want to stop processing the queue in the current cron-run and try again in the next one.

I'm not sure how to go about fixing this. For now, I've made a custom patch which adds a boolean "preventWatchdog" to the SuspendQueueException and in Cron.php, this is checked. I'll add the patch in the first comment.

Side note: watchdogs/exceptions/etc during cron-runs are being emailed, which results in quite some emails which are perfectly fine. I'd rather have an email when there really is a problem.

Issue fork drupal-2867001

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

SpadXIII created an issue. See original summary.

spadxiii’s picture

StatusFileSize
new1.15 KB
idebr’s picture

Status: Active » Needs review

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

dpi’s picture

Title: Allow peaceful suspending of the queue » Dont treat suspending of the queue as erroneous
Status: Needs review » Needs work

This is about the core Cron runner, which is especially noisy:

          catch (SuspendQueueException $e) {
            // If the worker indicates there is a problem with the whole queue,
            // release the item and skip to the next queue.
            $queue->releaseItem($item);

            watchdog_exception('cron', $e);

Right now the runner treats SuspendQueueException as erroneous, creating a watchdog exception. #2667294: Allow for peaceful requeueing simply changed the logic so RequeueException is caught, which prevented the default \Exception catch from logging as an exception.

I think the change here should remove the watchdog_exception call entirely, and at best log a normal ~debug-level log entry.

dpi’s picture

Issue summary: View changes
larowlan’s picture

I think the change here should remove the watchdog_exception call entirely, and at best log a normal ~debug-level log entry.

That seems reasonable to me.

dpi’s picture

Status: Needs work » Needs review
StatusFileSize
new10.55 KB
  • Changed to throwing SuspendQueueException no longer logs an error level log and backtrace: logs debug level log and no backtrace/exception.
  • Replaced "Broken/Problems/Crash" terms with "Suspend"
  • Added logging tests to new and existing cron queue tests.
  • Separated cron exception tests for isolation and to test logging reliably; removed use of deprecated functions.
  • Turned test queue worker IDs into constants similar to language negotiation plugins; improves DX.
dpi’s picture

Title: Dont treat suspending of the queue as erroneous » Dont treat suspending of a queue as erroneous
StatusFileSize
new11.15 KB

Lets try this.

dpi’s picture

Priority: Minor » Normal
StatusFileSize
new1.51 KB
new11 KB

Ninja CS fixes

neclimdul’s picture

Need to refresh some memory on expectations around this make sure it wouldn't break anyone's expectations but this seems to make sense. I think this may be similar to how drush is handling it already.

One thought skimming the patch, the "broken" test seems like it was probably valid just using the wrong exception. Is there another test that covers the handling of broken queues throwing exceptions or was it really only testing the suspend exception?

dpi’s picture

Is there another test that covers the handling of broken queues throwing exceptions

\Drupal\Tests\system\Kernel\System\CronQueueTest::testUncaughtExceptions makes use of a queue worker (\Drupal\cron_queue_test\Plugin\QueueWorker\CronQueueTestException) dedicated to throwing the generic \Exception.

The // Get the queue to test the specific SuspendQueueException. comment seems to indicate this was just for Suspend.

I think this may be similar to how drush is handling it already.

Right, Drush's current behavior in \Drush\Drupal\Commands\core\QueueCommands is to terminate by throwing an exception, which may end up in stdout. Nothing is logged.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

kim.pepper’s picture

Issue tags: +#pnx-sprint
mstrelan’s picture

StatusFileSize
new10.89 KB

Reroll of #16 against 9.3.x

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

acbramley made their first commit to this issue’s fork.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative

This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.

Appears the MR has test failures.

Have not yet reviewed.

acbramley’s picture

Status: Needs work » Needs review

I'm not sure what the old logs were before (with $this->anything() coming first) but now we just have our log and then the cron run completed notice.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs change record

Thanks.

Tagged for a change record to announce this new behavior.

The code changes look good to me so +1 there.

acbramley’s picture

Status: Needs work » Needs review
Issue tags: -Needs change record
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

perfect and adding the example really helped!

  • catch committed ccae3c04 on 10.1.x
    Issue #2867001 by dpi, acbramley, SpadXIII, mstrelan, smustgrave,...
catch’s picture

Category: Feature request » Task
Status: Reviewed & tested by the community » Fixed

Makes sense and the changes look good, more of a task than a feature.

Committed ccae3c0 and pushed to 10.1.x. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

quietone’s picture

Published change record.