Clearing a Clogged Action Scheduler Queue – WooCommerce

Clear out completed & cancelled actions safely

Would you like to clear out the Action Scheduler 3.0+ completed and cancelled actions in a safe way? You can add this filter to your site:

add_filter( 'action_scheduler_retention_period', function() { return DAY_IN_SECONDS * 14; } );

This will change the scheduled action retention period to 14 days (instead of the default 30 days). After your completed actions get down to a reasonable number, you can then remove that filter.

You could also shorten it to one day, wait a day, then remove it.

Clear out pending actions safely

Speed Up Processing

The best approach is to just speed up the processing of actions so that the queue completes.

There are a few approaches for this, from simplest to hardest:

  1. update WordPress, WooCommerce & Subscriptions. Specifically, if Subscriptions 3.0+, WooCommerce 4.0+, and WordPress 5.1+ are running, processing speeds should be much higher than with prior versions. If you aren’t already running those or another plugin that includes Action Scheduler 3.0+, the first step is to update to one of those. If you’re not sure, you can also load Action Scheduler 3.0+ as a standalone plugin:
  2. if the above doesn’t work, because it’s not processing actions fast enough, then it may be necessary to setup WP CLI runners. Two helpful guides on that:
    1. A general guide to using WP CLI:
    2. A specific guide for running Action Scheduler via WP CLI on Pantheon: (the general approach is transferrable to other hosts)

Note: we used to recommend the Action Scheduler high volume plugin:

This plugin will still work, but upgrading to AS 3.0+ will give all of the same benefits with the new async queue runner.

Clear out pending actions dangerously (you know what you’re doing)

NOTE: The queries below should be used at your own risk, on a staging site, etc.

Delete Data

If it’s not possible to speed up processing enough to clear the pending actions, then it may be necessary to clear the queue by deleting pending scheduled webhook actions.

This is only safe when you know the pending webhook actions aren’t necessary. For example, reporting plugins like Metorik use Webhooks as a backup data sync method, so they canbe safely synced. Some services will require these webhooks, in which case, it’s not safe to simply delete them.

To delete the actions:

  1. deleting logs and metadata for those scheduled webhook actions
  2. deleting all scheduled webhook actions

The queries to do this:

1. Delete logs for scheduled webhook actions

DELETE lg FROM wp_actionscheduler_logs lg
LEFT JOIN wp_actionscheduler_actions aa
ON aa.action_id = lg.action_id
WHERE aa.status LIKE 'pending'
AND aa.hook LIKE 'woocommerce_deliver_webhook_async'

2. Delete trashed scheduled webhook actions

DELETE FROM 'wp_actionscheduler_actions'
WHERE status = 'pending'

AND hook = 'woocommerce_deliver_webhook_async'

Other Helpful Queries

Query to find actions processed in a 1-hour window (update dates to suit):

FROM wp_actionscheduler_actions
WHERE status = 'complete'
AND last_attempt_gmt > '2020-05-08 06:30:00'
AND last_attempt_gmt < '2020-05-08 07:30:01'

Query to find pending actions in the past:

FROM wp_actionscheduler_actions
WHERE status = 'pending'
AND last_attempt_gmt < '2019-02-08 00:00:00'