Repository navigation
Stop loading Action Scheduler and turn off Stream's auto-purge - #489
Conversation
Audit log records are kept indefinitely in a write-only log, so Stream's purge job can never delete anything. Disable it and tell Stream to use WP-Cron (Cavalcade) rather than Action Scheduler, which makes our manual Action Scheduler setup and the disable-action-scheduler-cron option unnecessary. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
| // delete. Stop it being scheduled and use WP-Cron (Cavalcade) rather than Action Scheduler. | ||
| // Stream reads these filters when its plugin file loads, so they must be added first. | ||
| add_filter( 'wp_stream_enable_auto_purge', '__return_false' ); | ||
| add_filter( 'wp_stream_use_action_scheduler', '__return_false' ); |
There was a problem hiding this comment.
Sites that set disable-action-scheduler-cron: false will have Action Scheduler’s action_scheduler_run_queue event scheduled every minute. Action Scheduler is no longer loaded, so nothing will ever remove that event, and Cavalcade will keep running a job with no handler every minute.
Could we clear it once, only when no other plugin provides Action Scheduler? The class_exists check means a site running WooCommerce keeps its own queue runner.
add_action( 'init', function () {
if ( class_exists( 'ActionScheduler', false ) || get_option( 'altis_stream_as_cleanup' ) ) {
return;
}
wp_unschedule_hook( 'action_scheduler_run_queue' );
update_option( 'altis_stream_as_cleanup', 1 );
} );
If we’d rather not ship cleanup code, an upgrade note with wp cron event delete action_scheduler_run_queue would also work.
Related, and lower impact: the description says Stream clears purge jobs that earlier versions scheduled. That’s true for WP-Cron. For jobs stored in Action Scheduler’s tables, Stream only clears them when Action Scheduler’s functions are loaded (class-admin.php#L1104). Since we no longer load it, those rows stay in the actionscheduler_* tables. That’s harmless, because nothing runs them and the purge is blocked when it runs anyway. It might just be worth softening that line in the description.
There was a problem hiding this comment.
The reason someone might set disable-action-scheduler-cron: false is that they do want Actions Scheduler to run for another plugin. For example, WooCommerce. We only care to turn it off for Stream. If another plugin needs it, it will install its own copy and use that. That setting was to stop Altis from breaking that other plugin. Now we no longer interfere with other plugins' use of AS.
There was a problem hiding this comment.
I changed the comment above to make it clearer we are disabling the loading of Action scheduler only. The fact we disable auto purge means WP Cron won't get used either, but we don't need to say that.
There was a problem hiding this comment.
Fair point. Any site that set that flag has its own Action Scheduler handling the event, so it won’t be orphaned. Happy to drop this.
| } | ||
| // Records are kept indefinitely in a write-only log, so Stream's purge job has nothing to | ||
| // delete. Stop it being scheduled and use WP-Cron (Cavalcade) rather than Action Scheduler. | ||
| // Stream reads these filters when its plugin file loads, so they must be added first. |
There was a problem hiding this comment.
Nit: this is only true of wp_stream_use_action_scheduler. wp_stream_enable_auto_purge is read later, on wp_loaded (class-admin.php#L273) and when the purge runs. Maybe:
// `wp_stream_use_action_scheduler` is read when Stream's plugin file loads, so these must be added before the require.
| ``` | ||
| The Audit Log plugin (Stream) can use [Action Scheduler](https://actionscheduler.org/) for deferred work, but Altis does not load it. Audit Log records are kept indefinitely, so Altis turns off Stream's automatic purge, and Stream uses WP-Cron for any deferred work instead. | ||
|
|
||
| Other plugins can continue to use Action Scheduler if they need it, such as WooCommerce, which loads its own copy. Altis does not interfere with them. |
There was a problem hiding this comment.
Nit: this changes behaviour for sites running WooCommerce or another plugin that bundles Action Scheduler. Their queue runner and the Tools → Scheduled Actions menu now work, where we used to suppress them. That’s the right outcome, it would be good if we could add it to the release notes or changelog, so it doesn’t surprise anyone?
There was a problem hiding this comment.
That's what the disable-action-scheduler-cron: false was for. If our previous default behaviour broke things for another site's plugins, they will have needed to set that setting to stop us breaking things. Now we don't turn it off. So they no longer need the setting.
|
Successfully created backport PR for |
|
Successfully created backport PR for |
|
Successfully created backport PR for |
|
Successfully created backport PR for |
Since 4.2.0, Stream purges old records through Action Scheduler, which we avoid because it interferes with Cavalcade. We keep records indefinitely in a write-only log, so the purge can never delete anything and only adds a recurring job.
Stream 4.3.0 added
wp_stream_enable_auto_purgeandwp_stream_use_action_schedulerfor this case. Both are now set to false before Stream loads. Stream clears any purge job that earlier versions scheduled, and no longer loads Action Scheduler, so the manual setup, the queue-runner cron removal and the Scheduled Actions menu removal are deleted.Effect on sites: the
extra.altis.modules.security.disable-action-scheduler-cronsetting no longer does anything and is documented as safe to remove. Plugins that bundle their own Action Scheduler, such as WooCommerce, now run normally, where the old workaround suppressed their queue runner.Part of humanmade/product-dev#2078.
🤖 Generated with Claude Code