[wp-trac] [WordPress Trac] #49693: Drop duplicate recurring cron events
WordPress Trac
noreply at wordpress.org
Wed Apr 8 16:50:36 UTC 2020
#49693: Drop duplicate recurring cron events
-------------------------------------------------+-------------------------
Reporter: aidvu | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: 5.5
Component: Cron API | Version: 5.4
Severity: normal | Resolution:
Keywords: has-patch has-unit-tests needs- | Focuses:
testing needs-refresh |
-------------------------------------------------+-------------------------
Comment (by aidvu):
I'm inclined to say 42. :D
> In terms of patch, the timestamp allowance will be similar to the ten
minute calculation for single events: ie, min and max time stamp may be
greater than 24 hours apart depending on when the event is being
scheduled.
Thinking about this, I'm not sure a fixed number is what we need... Let's
say, someone creates a custom event that runs every 5 seconds (like the
example on [https://developer.wordpress.org/plugins/cron/understanding-wp-
cron-scheduling/ wp.org docs]). Should probably be based on the interval,
with a sane "maximum" for events that run fewer times.
Not sure about the same calculation as for single-events. I had this in
mind.
{{{#!php
// Always allow 24 occurrences per interval, even if it's an event
with long $interval.
$allowed_occurrences = 24;
if ( 24 < DAY_IN_SECONDS / $interval ) {
// Set a per-day limit based on the interval
$allowed_occurrences = DAY_IN_SECONDS / $interval;
}
$check_interval = DAY_IN_SECONDS;
if ( $check_interval < $event->interval ) {
$check_interval = $event->interval;
}
$min_timestamp = $event->timestamp - ( $check_interval / 2 );
$max_timestamp = $event->timestamp + ( $check_interval / 2 );
$occurrences = 0;
foreach ( $crons as $event_timestamp => $cron ) {
if ( $event_timestamp < $min_timestamp ) {
continue;
}
if ( $event_timestamp > $max_timestamp ) {
break;
}
if ( isset( $cron[ $event->hook ][ $key ] ) ) {
$occurrences++;
break;
}
}
if ( $allowed_occurrences < $occurrences ) {
return false;
}
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/49693#comment:13>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list