[wp-trac] [WordPress Trac] #57271: Cron unschedule / reschedule event errors
WordPress Trac
noreply at wordpress.org
Tue Jan 30 09:25:38 UTC 2024
#57271: Cron unschedule / reschedule event errors
----------------------------------------+------------------------------
Reporter: domainsupport | Owner: audrasjb
Type: defect (bug) | Status: assigned
Priority: normal | Milestone: Awaiting Review
Component: Cron API | Version: 6.0
Severity: normal | Resolution:
Keywords: has-patch needs-unit-tests | Focuses:
----------------------------------------+------------------------------
Comment (by domainsupport):
@galbaras We rarely see this error anymore but when we do see it it always
points to some kind of issue with the database (usually a lack of
resources, temporary or otherwise) which prevents the cron from being
saved into the options table.
It's not a welcome explanation to some but we have yet to find a situation
where this has not been the route cause.
We created a plugin to detect cron schedules that have no associated
actions and find it to be very common that plugins forget to register a
deactivation hook to clean up their cron schedules. So common that we have
even found and raised issues with [https://wordpress.org/support/topic/wp-
cron-event-left-after-deactivation/ WPForms],
[https://wordpress.org/support/topic/wp-cron-
monsterinsights_usage_tracking_cron-not-being-removed/ MonsterInsights],
[https://wordpress.org/support/topic/wp-cron-
googlesitekit_cron_update_remote_features-not-being-removed/ Site Kit by
Google] and even [https://wordpress.org/support/topic/wp-cron-
jetpack_v2_heartbeat-not-being-removed/ Jetpack]!
Duplicate cron schedule entries are also usually attributed to plugin
error (or a race condition) which we have also seen fairly regularly. We
don't know of a way to "rebuild" the cron schedule but our previously
mentioned plugin uses this to remove empty cron schedules if it is of use
...
{{{#!php
<?php
$empty_event_hooks =
wordpress_maintenance_get_empty_cron_event_hooks();
foreach ($empty_event_hooks as $hook) {
wp_clear_scheduled_hook($hook);
}
function wordpress_maintenance_get_empty_cron_event_hooks() {
$cron_events = _get_cron_array();
$empty_event_hooks = array();
if (is_array($cron_events)) {
global $wp_filter;
foreach ($cron_events as $cron_event) {
foreach ($cron_event as $hook => $value) {
if ('wc_admin_unsnooze_admin_notes' !== $hook
&&!isset($wp_filter[$hook])) {
$empty_event_hooks[] = $hook;
}
}
}
}
return array_unique($empty_event_hooks);
}
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/57271#comment:45>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list