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'

9 responses to “Clearing a Clogged Action Scheduler Queue – WooCommerce”

  1. I appreciate the help on this, but you fail to tell us which file
    add_filter( ‘action_scheduler_retention_period’, function() { return DAY_IN_SECONDS * 14; } );
    goes into. Config file, .htaccess file?

  2. Hi,

    I use a plugin to import products and all data is kept live by the plugin. When I receive an order, the order is automatically forwarded to the suppliers, at least that is the intention. When i have an order , one of the scheduled actions is suppose check the order and must forward it to the supplier but there is 1 action that keeps coming back so that the other actions are not executed. That’s the “woocommerce_deliver_webhook_async”. I recently had 100k of those actions pending and because of that the other actions were not executed. And since yesterday it started again. It is just keeps going up. My question is: what is this “woocommerce_deliver_webhook_async” for? What does it do? Why does the action keep coming back? Is it possible to fire them directly? And is it possible to turn them off, what happens then? I’m not an advanced programmer and I don’t know what to do. I searched a lot on the internet but couldn’t really find anything. Only this article ( where you can fire them directly or how to turn it off. Can you please help me. I having this problem since I’m building my website. I contacted Woocommerce and they redirected me to your webpage. I would really appreciate it if you could help me. Thanks in advance.

    • The ‘woocommerce_deliver_webhook_async’ actions are simply scheduled actions that deliver a payload to a webhook. It’s a generically-named action that could be created by any 3rd-party plugin which needs data delivered to it. For example, a 3rd-party reporting plugin which receives data after every time a subscription is updated, etc.

      In this case, it seems like that plugin is creating a massive amount of webhook actions, and that perhaps those actions are failing, or causing problems. You might go to **WooCommerce > settings > advanced > webhooks** and take a look at the webhooks that are active there. If there are redundant ones, one which are for a plugin that you no longer use, or ones that you can identify as causing problems, then that’s where you’d delete or turn them off.

  3. Hello Nick

    I have read your tutorial above and tried it.

    I have a big problem, my queue on Woocommerce is overflowing and I want to delete the queue.

    I tried Automattic’s Action Scheduler and it took 3 weeks last time my list had 100,000 waiting actions. That is too long for me.

    So, as you wrote in your comment, I installed the code snippets plugin and enter the code to delete the wading actions.

    DELETE FROM ‘wp_actionscheduler_actions’
    WHERE status = ‘pending’
    AND hook = ‘woocommerce_deliver_webhook_async’

    but it just comes a message from wordpress that the code would make a fatal error and it aborts directly.

    Is there any other code or way to solve this problem?

    I would appreciate a feedback from you

    best regards Fuad.

    • The code that you tried adding to your snippets is an SQL command, and that would have to be run from some place you can run SQL commands, like phpmyadmin. I don’t recommend using those commands unless you know what you’re doing, as you would be deleting data directly from your database.

      However, it seems to me that if you have 100,000 waiting actions, then there is something more wrong with your site that is preventing the actions from running properly. I would suggest first trying to pin down what is causing all of your actions to back up, before focusing on the symptom of a backed-up queue.

    • You could run the SQL commands that I listed in section 2 of this post, just modify the ‘pending’ to ‘failed’, and remove the last line on each one regarding the hook. However, if running SQL commands is out of your wheelhouse, I would recommend getting help from a more experienced developer. Best of luck!

Leave a Reply

Your email address will not be published. Required fields are marked *