Last active
September 21, 2024 15:46
-
-
Save charmoney/4273a0c5222f622ab1aba6c290a16f1a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* The ActionScheduler WordPress plugin removes 20 complete & canceled status actions older than | |
* the filtered `action_scheduler_retention_period` value in seconds. In large scale applications | |
* generating more than 20 actions per minute on average, this can cause run away growth of the | |
* wp_actionscheduler_actions and wp_actionscheduler_logs tables. | |
* | |
* This gist adds a second cleanup pass every time AS normally cleans up & runs the queue. | |
* | |
* No support provided. No warranties expressed or implied. | |
* | |
* @author Chris Harmoney <chris@cornershopcreative.com> | |
*/ | |
if ( ! defined( 'ABSPATH' ) ) { | |
die( 'Direct access not allowed' ); | |
} | |
/** | |
* Change Action Scheduler default purge to 2 days | |
*/ | |
function charmoney_gist_action_scheduler_retention_period() { | |
return 2 * DAY_IN_SECONDS; | |
} | |
add_filter( 'action_scheduler_retention_period', 'charmoney_gist_action_scheduler_retention_period' ); | |
/** | |
* Manually purge additional old completed AS records to prevent runaway table growth. | |
*/ | |
function charmoney_gist_as_rq_extra_purge() { | |
$clean = 1000; | |
$cleaner = new \ActionScheduler_QueueCleaner( null, $clean ); | |
$cleaner->delete_old_actions(); | |
} | |
add_action( 'action_scheduler_run_queue', 'charmoney_gist_as_rq_extra_purge', 999 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment