Site Health Check: Increase time allowance for cron checks.
Introduces `WP_Site_Health::has_late_cron()` for late wp-cron jobs and extends the time allowance before a job is considered missed. In a standard configuration using loopback requests, a job is considered late once past due and missed over five minutes past due. Late and missed time frames are extended if `DISABLE_WP_CRON` is defined as `true` to allow for crontab tasks running less frequently. A job is considered late once it's 15 minutes past due and missed over one hour past due. A file for site health unit tests has been introduced with tests for cron in critical, late and missed states. Props rockfire, afragen, peterwilsoncc. Fixes #47223. Built from https://develop.svn.wordpress.org/trunk@45801 git-svn-id: http://core.svn.wordpress.org/trunk@45612 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
b8c5530131
commit
a56256d158
|
@ -19,6 +19,9 @@ class WP_Site_Health {
|
|||
public $schedules;
|
||||
public $crons;
|
||||
public $last_missed_cron = null;
|
||||
public $last_late_cron = null;
|
||||
private $timeout_missed_cron = null;
|
||||
private $timeout_late_cron = null;
|
||||
|
||||
/**
|
||||
* WP_Site_Health constructor.
|
||||
|
@ -28,6 +31,14 @@ class WP_Site_Health {
|
|||
public function __construct() {
|
||||
$this->prepare_sql_data();
|
||||
|
||||
$this->timeout_late_cron = 0;
|
||||
$this->timeout_missed_cron = - 5 * MINUTE_IN_SECONDS;
|
||||
|
||||
if ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ) {
|
||||
$this->timeout_late_cron = - 15 * MINUTE_IN_SECONDS;
|
||||
$this->timeout_missed_cron = - 1 * HOUR_IN_SECONDS;
|
||||
}
|
||||
|
||||
add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) );
|
||||
|
||||
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
|
||||
|
@ -1416,8 +1427,7 @@ class WP_Site_Health {
|
|||
$this->has_missed_cron()->get_error_message()
|
||||
)
|
||||
);
|
||||
} else {
|
||||
if ( $this->has_missed_cron() ) {
|
||||
} elseif ( $this->has_missed_cron() ) {
|
||||
$result['status'] = 'recommended';
|
||||
|
||||
$result['label'] = __( 'A scheduled event has failed' );
|
||||
|
@ -1430,7 +1440,19 @@ class WP_Site_Health {
|
|||
$this->last_missed_cron
|
||||
)
|
||||
);
|
||||
}
|
||||
} elseif ( $this->has_late_cron() ) {
|
||||
$result['status'] = 'recommended';
|
||||
|
||||
$result['label'] = __( 'A scheduled event is late' );
|
||||
|
||||
$result['description'] = sprintf(
|
||||
'<p>%s</p>',
|
||||
sprintf(
|
||||
/* translators: %s: The name of the late cron event. */
|
||||
__( 'The scheduled event, %s, is late to run. Your site still works, but this may indicate that scheduling posts or automated updates may not work as intended.' ),
|
||||
$this->last_late_cron
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
@ -1926,7 +1948,7 @@ class WP_Site_Health {
|
|||
}
|
||||
|
||||
foreach ( $this->crons as $id => $cron ) {
|
||||
if ( ( $cron->time - time() ) < 0 ) {
|
||||
if ( ( $cron->time - time() ) < $this->timeout_missed_cron ) {
|
||||
$this->last_missed_cron = $cron->hook;
|
||||
return true;
|
||||
}
|
||||
|
@ -1935,6 +1957,33 @@ class WP_Site_Health {
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if any scheduled tasks are late.
|
||||
*
|
||||
* Returns a boolean value of `true` if a scheduled task is late and ends processing. If the list of
|
||||
* crons is an instance of WP_Error, return the instance instead of a boolean value.
|
||||
*
|
||||
* @return bool|WP_Error true if a cron is late, false if it wasn't. WP_Error if the cron is set to that.
|
||||
*/
|
||||
public function has_late_cron() {
|
||||
if ( is_wp_error( $this->crons ) ) {
|
||||
return $this->crons;
|
||||
}
|
||||
|
||||
foreach ( $this->crons as $id => $cron ) {
|
||||
$cron_offset = $cron->time - time();
|
||||
if (
|
||||
$cron_offset >= $this->timeout_missed_cron &&
|
||||
$cron_offset < $this->timeout_late_cron
|
||||
) {
|
||||
$this->last_late_cron = $cron->hook;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run a loopback test on our site.
|
||||
*
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '5.3-alpha-45800';
|
||||
$wp_version = '5.3-alpha-45801';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue