class-scheduler.php

Scheduler boundary — Action Scheduler unique-job helpers and stampede locks.

Source includes/Scheduler/class-scheduler.php5 min readPart of Performance Optimisation

includes/Scheduler/class-scheduler.php

Scheduler boundary — Action Scheduler unique-job helpers and stampede locks.

Namespace: PerformanceOptimise\\Inc · Lines: 636

Class Scheduler

Class Scheduler

Source: includes/Scheduler/class-scheduler.php, line 59

final class Scheduler

Tags: @since 2.4.0

Properties

PropertyVisibilityTypeDefaultLine
$as_unique_supportprivate static?boolnull69
$as_unique_arityprivate staticarrayarray()79

publicstatic supports_action_scheduler_unique()

public static function supports_action_scheduler_unique(): bool

Whether the loaded Action Scheduler supports atomic unique actions.

Return: bool — True when the `$unique` parameter may be passed.

Tags: @since 2.2.0

Source: includes/Scheduler/class-scheduler.php, line 101

publicstatic reset_action_scheduler_unique_cache()

public static function reset_action_scheduler_unique_cache(): void

Reset the memoized Action Scheduler unique-support probes.

Return: void.

Tags: @since 2.2.0

Source: includes/Scheduler/class-scheduler.php, line 119

privatestatic probe_action_scheduler_unique()

private static function probe_action_scheduler_unique(): bool

Unmemoized Action Scheduler unique-support probe.

Return: bool — True when the `$unique` parameter may be passed.

Tags: @since 2.2.0

Source: includes/Scheduler/class-scheduler.php, line 130

privatestatic function_has_unique_param()

private static function function_has_unique_param(string $function_name, int $min_params): bool

Whether a scheduler function accepts the AS 4.x `$unique` parameter.

ParameterTypeDefaultDescription
$function_namestring—Function name to inspect.
$min_paramsint—Minimum parameter count that implies `$unique` support.

Return: bool — True when the function exists and declares at least `$min_params` parameters.

Tags: @since 2.2.0

Source: includes/Scheduler/class-scheduler.php, line 166

privatestatic as_already_scheduled()

private static function as_already_scheduled(string $hook, array $args, string $group): bool

Fail-open \”already scheduled\” guard shared by the unique helpers.

ParameterTypeDefaultDescription
$hookstring—Action hook.
$argsarray—Action arguments.
$groupstring—Action group.

Return: bool — True when a matching action is already scheduled.

Tags: @since 2.2.0

Source: includes/Scheduler/class-scheduler.php, line 199

privatestatic as_already_scheduled_in_any_group()

private static function as_already_scheduled_in_any_group(string $hook, array $args, string $group, array=array() $extra_groups): bool

Fail-open \”already scheduled\” check across several AS groups.

ParameterTypeDefaultDescription
$hookstring—Action hook.
$argsarray—Action arguments.
$groupstring—Primary action group.
$extra_groupsarray=array()—Additional groups to probe.

Return: bool — True when a matching action is already scheduled in any of the groups.

Tags: @since 2.2.0

Source: includes/Scheduler/class-scheduler.php, line 229

publicstatic enqueue_unique_async_action()

public static function enqueue_unique_async_action(string $hook, array=array() $args, string=\'\' $group, array=array() $extra_groups): int

Enqueue an async Action Scheduler job with atomic dedup when available.

ParameterTypeDefaultDescription
$hookstring—Action hook.
$argsarray=array()—Action arguments.
$groupstring=\'\'—Action group.
$extra_groupsarray=array()—Additional groups probed by the legacy fallback guard (e.g. the CCSS legacy group).

Return: int — Action ID, or 0 when deduped, unavailable, or on failure.

Tags: @since 2.2.0

Source: includes/Scheduler/class-scheduler.php, line 260

publicstatic schedule_unique_single_action()

public static function schedule_unique_single_action(int $timestamp, string $hook, array=array() $args, string=\'\' $group, array=array() $extra_groups): int

Schedule a one-off Action Scheduler job with atomic dedup when available.

ParameterTypeDefaultDescription
$timestampint—When the job will run.
$hookstring—Action hook.
$argsarray=array()—Action arguments.
$groupstring=\'\'—Action group.
$extra_groupsarray=array()—Additional groups probed by the legacy fallback guard (e.g. the CCSS legacy group).

Return: int — Action ID, or 0 when deduped, unavailable, or on failure.

Tags: @since 2.2.0

Source: includes/Scheduler/class-scheduler.php, line 312

publicstatic next_scheduled()

public static function next_scheduled(string $hook, array=array() $args)

Probe when a WP-Cron event is next scheduled.

ParameterTypeDefaultDescription
$hookstring—Cron hook name.
$argsarray=array()—Optional event args.

Return: int|false — Timestamp of the next run, or false when unscheduled/unavailable.

Tags: @since 2.4.0

Source: includes/Scheduler/class-scheduler.php, line 361

publicstatic schedule_recurring_event()

public static function schedule_recurring_event(string $hook, int $timestamp, string $recurrence, array=array() $args): bool

Schedule a recurring WP-Cron event once (idempotent).

ParameterTypeDefaultDescription
$hookstring—Cron hook name.
$timestampint—First run timestamp (e.g. `time()`).
$recurrencestring—Schedule recurrence (e.g. `daily`).
$argsarray=array()—Optional event args (dedup is per args-set).

Return: bool — True when already scheduled or newly scheduled, false when unavailable/failed.

Tags: @since 2.4.0

Source: includes/Scheduler/class-scheduler.php, line 389

publicstatic schedule_single_event()

public static function schedule_single_event(int $timestamp, string $hook, array=array() $args): bool

Schedule a one-off WP-Cron event.

ParameterTypeDefaultDescription
$timestampint—When the event will run.
$hookstring—Cron hook name.
$argsarray=array()—Optional event args.

Return: bool — True on schedule, false when unavailable/failed.

Tags: @since 2.4.0

Source: includes/Scheduler/class-scheduler.php, line 421

publicstatic is_stampede_guard_enabled()

public static function is_stampede_guard_enabled(): bool

Whether the stampede guard is enabled.

Return: bool — True when coalescing is active.

Tags: @since 2.2.0

Source: includes/Scheduler/class-scheduler.php, line 444

publicstatic stampede_lock_ttl()

public static function stampede_lock_ttl(): int

Effective stampede lock TTL in seconds, clamped to 2-5s.

Return: int — Lock TTL clamped to 2-5 seconds.

Tags: @since 2.2.0

Source: includes/Scheduler/class-scheduler.php, line 473

publicstatic generate_stampede_owner()

public static function generate_stampede_owner(): string

Generate a unique stampede lock owner token.

Return: string — Unique owner token (never empty).

Tags: @since 2.2.0

Source: includes/Scheduler/class-scheduler.php, line 507

publicstatic acquire_stampede_lock()

public static function acquire_stampede_lock(string $lock_key, string $owner, int=5 $ttl, string=\'wppo\' $group): bool

Atomically acquire a named stampede lock.

ParameterTypeDefaultDescription
$lock_keystring—Blog-aware lock key (use transient_key()).
$ownerstring—Unique owner token from generate_stampede_owner().
$ttlint=5—Lock TTL in seconds (clamped to 2-5s; best-effort bound — rebuilds slower than the TTL, e.g. a slow- origin telemetry fetch, may let the lock expire mid-rebuild and duplicate work).
$groupstring=\'wppo\'—Object-cache group for the lock.

Return: bool — True when this worker owns the lock.

Tags: @since 2.2.0

Source: includes/Scheduler/class-scheduler.php, line 553

publicstatic release_stampede_lock()

public static function release_stampede_lock(string $lock_key, string $owner, string=\'wppo\' $group): void

Release a stampede lock only when this worker still owns it.

ParameterTypeDefaultDescription
$lock_keystring—Blog-aware lock key.
$ownerstring—Owner token that acquired the lock.
$groupstring=\'wppo\'—Object-cache group for the lock.

Return: void.

Tags: @since 2.2.0

Source: includes/Scheduler/class-scheduler.php, line 600

Hooks

Hooks referenced in includes/Scheduler/class-scheduler.php:

HookTypeLineNotes
wppo_stampede_guard_enabledfilter457@param ×1
wppo_stampede_lock_ttlfilter488@param ×1