# Action Scheduler clean up

- Link: https://cagrimmett.com/2026/02/12/action-scheduler-clean-up/
- Published: 2026-02-12T22:53:22-05:00
- Author: Chuck Grimmett

[Action Scheduler](https://actionscheduler.org/) is a library for triggering a WordPress
hook to run at some time in the future. It is used in a lot of large plugins to 
handle background processing of large job queues. It is an extremely useful tool.
Unfortunately, it is also easy for bugs to make the queue or logs explode in size.

I had a fun runaway action scheduler issue to deal with at work today that ended
up creating **26.7M** rows in the `wp_actionscheduler_actions` table before we patched
the bug, so I had to figure out how to clean it up. I’m blogging about what I learned
so future me can doesn’t have to figure it out again.

### Action Scheduler Defaults

By default, after every run, Action Scheduler cleans up completed and canceled actions
older than 31 days. It _does not_ clean up failed actions by default. Failed actions
will stay in the `wp_actionscheduler_actions` table until manually cleaned up.

You can change the default retention period or statuses that are cleaned up with
filters:

`action_scheduler_default_cleaner_statuses`

`action_scheduler_retention_period`

### Action Scheduler CLI

`wp action-scheduler clean`

`wp action-scheduler clean --batch-size=500 --batches=1000`

`wp action-scheduler clean --status=failed --batch-size=50 --before='90 days ago'`

### Bash

Bash and sql to delete 50K rows at a time with 2s delay after each delete, pausing
to re-assess every 1M rows:

    ```wp-block-code
    for i in $(seq 1 20); do echo "Batch $i/20..."; wp db query "DELETE FROM wp_actionscheduler_actions WHERE status = 'canceled' LIMIT 50000;"; sleep 2; done
    ```

### Truncate

The fastest option.

 1. Export pending actions
 2. `TRUNCATE TABLE wp_actionscheduler_actions;`
 3. Import pending actions

---

### Processing backed up queues

 1. First try [https://github.com/woocommerce/action-scheduler-high-volume](https://github.com/woocommerce/action-scheduler-high-volume)
 2. When all else fails, [use the CLI](https://actionscheduler.org/wp-cli/), increase
    the batch size, `--force`, and if it is big enough to have multiple runs going,
    make it more efficient by having each run focus on a different group or hook.

## Comments

### By: SethLife

- Link: https://cagrimmett.com/2026/02/12/action-scheduler-clean-up/#comment-44074
- Published: 2026-05-25T09:05:06-04:00

Thank you, I used the fastest option. The first thing I did to grab the pending 
items, was use:

SELECT \* FROM `wp_actionscheduler_actions`
 WHERE `status` \= ‘pending’;

Just in case someone needs that.

Loading...
