[wp-trac] [WordPress Trac] #44818: cron: preventing duplicate events fails when the first event is too far in the past

WordPress Trac noreply at wordpress.org
Mon Oct 1 23:31:45 UTC 2018


#44818: cron: preventing duplicate events fails when the first event is too far in
the past
-------------------------------------------------+-------------------------
 Reporter:  bodohugobarwich                      |       Owner:
                                                 |  peterwilsoncc
     Type:  defect (bug)                         |      Status:  assigned
 Priority:  normal                               |   Milestone:  5.0
Component:  Cron API                             |     Version:  2.7
 Severity:  normal                               |  Resolution:
 Keywords:  has-patch has-unit-tests needs-      |     Focuses:
  refresh                                        |
-------------------------------------------------+-------------------------

Comment (by peterwilsoncc):

 > Do you want me to do the change or have you already written something
 that I would checkout?

 I haven't written anything yet, if you have the time it would be great if
 you could refactor it.

 > But about setting `$mintimestamp` to `0` this would make match
 `$requested_timestamp` against any already scheduled event lesser than
 `$maxtimestamp`
 > While the Requirement was that any event can be scheduled if there isn't
 any similar event already scheduled within `10 min` of it.

 The [https://core.trac.wordpress.org/browser/trunk/src/wp-
 cron.php?rev=43663&marks=106-141#L106 loop that spawns cron jobs] does so
 for any event with a time stamp between `0` and `time()`.

 The effect of this is that events scheduled at `-30 min`, `-3 min` and
 `time()` will all run at the same time. To avoid effectively scheduling
 single events to happen within ten minutes of another, the logic would be:

 {{{#!php
 <?php

 if ( $requested_timestamp < time() + 10 * MINUTE_IN_SECONDS ) {
   $mintimestamp = 0;
 } else {
   $mintimestamp = $requested_timestamp - 10 * MINUTE_IN_SECONDS;
 }
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/44818#comment:16>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list