Cron_Health
Detects conditions that can prevent the background queue from advancing.
WordPress runs _wp_cron() on shutdown, so a screen reading the schedule
always sees it as it stood before this request spawned cron. An overdue event
therefore proves nothing on its own. This class instead records when the
worker last ran and when the queue was last observed with work in it, and
reports trouble only once cron has had a whole observation window to act.
Namespace: WebberZone\Image_Optimizer
Since: 1.1.0
Source: includes/class-cron-health.php line 25
Methods
record_run() static
Note that the background worker ran.
Since: 1.1.0
Line: 85
static public function record_run( ): void;
Returns: void
get_status() static
Get the current site’s background queue cron status.
Records an observation as a side effect, since a stall can only be told apart from a quiet site by comparing two looks at the queue.
Since: 1.1.0
Line: 99
static public function get_status( ): string;
Returns: string — One of the class status constants.
forget() static
Discard any open observation.
Called when the worker is switched off or the plugin is deactivated, so a window opened before that is not mistaken for a stall on the way back.
Since: 1.1.0
Line: 127
static public function forget( ): void;
Returns: void
is_wp_cron_disabled() static
Whether page-load cron spawning is switched off.
Since: 1.1.0
Line: 138
static public function is_wp_cron_disabled( ): bool;
Returns: bool — True when DISABLE_WP_CRON is defined and truthy.
determine_status() static
Determine cron health from an observed worker history and queue state.
Kept separate from get_status() so Site Health and tests can apply the same rule without duplicating it.
Since: 1.1.0
Line: 157
static public function determine_status( bool $wp_cron_disabled, int $remaining, int $last_run, int $observed_at, int $now ): string;
| Type | Name | Description |
|---|---|---|
bool |
$wp_cron_disabled |
Whether DISABLE_WP_CRON is truthy. |
int |
$remaining |
Pending and processing queue rows. |
int |
$last_run |
Unix timestamp of the last worker run, 0 when never. |
int |
$observed_at |
Unix timestamp of the last observation, 0 when never. |
int |
$now |
Current Unix timestamp. |
Returns: string — One of the class status constants.
next_observation() static
Work out the observation to carry forward.
An observation is kept until the worker runs, so the window it opened measures cron’s failure to act rather than the site’s lack of traffic.
Since: 1.1.0
Line: 183
static public function next_observation( int $remaining, int $last_run, int $observed_at, int $now ): int;
| Type | Name | Description |
|---|---|---|
int |
$remaining |
Pending and processing queue rows. |
int |
$last_run |
Unix timestamp of the last worker run, 0 when never. |
int |
$observed_at |
Unix timestamp of the last observation, 0 when never. |
int |
$now |
Current Unix timestamp. |
Returns: int — Observation timestamp to store, 0 to forget it.