Skip to content

Commit eb60152

Browse files
committed
Improve inline documentation for the cron lock behavior.
Props ericlewis. Fixes #32478. git-svn-id: https://develop.svn.wordpress.org/trunk@32580 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 2c32eff commit eb60152

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

src/wp-cron.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ function _get_cron_lock() {
6464
if ( isset($keys[0]) && $keys[0] > $gmt_time )
6565
die();
6666

67-
$doing_cron_transient = get_transient( 'doing_cron');
67+
68+
// The cron lock: a unix timestamp from when the cron was spawned.
69+
$doing_cron_transient = get_transient( 'doing_cron' );
6870

6971
// Use global $doing_wp_cron lock otherwise use the GET lock. If no lock, trying grabbing a new lock.
7072
if ( empty( $doing_wp_cron ) ) {
@@ -79,7 +81,10 @@ function _get_cron_lock() {
7981
}
8082
}
8183

82-
// Check lock
84+
/*
85+
* The cron lock (a unix timestamp set when the cron was spawned),
86+
* must match $doing_wp_cron (the "key").
87+
*/
8388
if ( $doing_cron_transient != $doing_wp_cron )
8489
return;
8590

src/wp-includes/cron.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,12 @@ function spawn_cron( $gmt_time = 0 ) {
225225
return;
226226

227227
/*
228-
* multiple processes on multiple web servers can run this code concurrently
229-
* try to make this as atomic as possible by setting doing_cron switch
230-
*/
228+
* Get the cron lock, which is a unix timestamp of when the last cron was spawned
229+
* and has not finished running.
230+
*
231+
* Multiple processes on multiple web servers can run this code concurrently,
232+
* this lock attempts to make spawning as atomic as possible.
233+
*/
231234
$lock = get_transient('doing_cron');
232235

233236
if ( $lock > $gmt_time + 10 * MINUTE_IN_SECONDS )
@@ -266,6 +269,7 @@ function spawn_cron( $gmt_time = 0 ) {
266269
return;
267270
}
268271

272+
// Set the cron lock with the current unix timestamp, when the cron is being spawned.
269273
$doing_wp_cron = sprintf( '%.22F', $gmt_time );
270274
set_transient( 'doing_cron', $doing_wp_cron );
271275

0 commit comments

Comments
 (0)