The Scheduled Actions that sit in WooCommerce Action Scheduler can get stuck with thousands of actions piling up, just stuck in a failed, canceled, pending or complete state. This can result in bloated database tables in particular wp_actionscheduler_actions and wp_actionscheduler_logs tables.

Woocommerce Scheduled Actions

Large number of canceled, failed and completed Scheduled Actions

 

Since the states of failed, canceled or complete are already passed, you would be safe to remove them from the wp_actionscheduler_actions table. You can do so in phpMyadmin SQL tab.

Woocommerce Scheduled Actions Database Table

Removing all canceled actions.

 

Just use the state required in the SQL command…

DELETE FROM `wp_actionscheduler_actions` WHERE `status` = 'canceled'
DELETE FROM `wp_actionscheduler_actions` WHERE `status` = 'failed'
DELETE FROM `wp_actionscheduler_actions` WHERE `status` = 'complete'

For scheduled actions that are pending you can use the same SQL commands as above just change the status to pending, but you would probably leave these to run in time or if they are overdue then run them from within WooCommerce.

 

Woocommerce Scheduled Actions Pending Run

Run pending actions now

 

wp_actionscheduler_logs Table

If the wp_actionscheduler_logs table is bloated, just empty it.

Woocommerce Scheduled Actions Log Table

Empty the log table

 

Completed Actions

Completed actions are normally removed by the Action Scheduler after 30 days by default but there is a filter that can change that setting  –action_scheduler_retention_period, use it like so in functions.php

add_filter( 'action_scheduler_retention_period', 'wpb_action_scheduler_purge' );
/**
 * Change Action Scheduler default purge to 1 week
 */
function wpb_action_scheduler_purge() {
 return WEEK_IN_SECONDS;
}

3 Comments

  1. Nick on June 18, 2020 at 11:24 am

    Thanks for your post. You can run all 3 quickly with `DELETE FROM `wp_actionscheduler_actions` WHERE `status` IN (‘canceled’, ‘failed’, ‘complete’);`

  2. Scott on June 4, 2020 at 6:57 pm

    Hi, thanks for writing on this topic. I find that every time I update Woocommerce, on nearly every store I have, the database updates never finish on their own, and I discover many pending actions stuck in the scheduler. Is this common? If not, what issues should I be looking for that would cause this?

  3. Brigitte on April 14, 2020 at 2:21 pm

    Thank you so much for this useful contribution. I used it already a few times. Very helpful!

Leave a Comment