includes/Scheduler/class-scheduler.php
Scheduler boundary — Action Scheduler unique-job helpers and stampede locks.
Class Scheduler
Class Scheduler
final class SchedulerProperties
| Property | Visibility | Type | Default | Line |
|---|---|---|---|---|
$as_unique_support | private static | ?bool | null | 69 |
$as_unique_arity | private static | array | array() | 79 |
publicstatic supports_action_scheduler_unique()
public static function supports_action_scheduler_unique(): boolWhether the loaded Action Scheduler supports atomic unique actions.
Return: bool — True when the `$unique` parameter may be passed.
publicstatic reset_action_scheduler_unique_cache()
public static function reset_action_scheduler_unique_cache(): voidReset the memoized Action Scheduler unique-support probes.
Return: void.
privatestatic probe_action_scheduler_unique()
private static function probe_action_scheduler_unique(): boolUnmemoized Action Scheduler unique-support probe.
Return: bool — True when the `$unique` parameter may be passed.
privatestatic function_has_unique_param()
private static function function_has_unique_param(string $function_name, int $min_params): boolWhether a scheduler function accepts the AS 4.x `$unique` parameter. Parameter Type Default Description $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.
privatestatic as_already_scheduled()
private static function as_already_scheduled(string $hook, array $args, string $group): boolFail-open \”already scheduled\” guard shared by the unique helpers. Parameter Type Default Description $hookstring— Action hook. $argsarray— Action arguments. $groupstring— Action group.
Return: bool — True when a matching action is already scheduled.
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): boolFail-open \”already scheduled\” check across several AS groups. Parameter Type Default Description $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.
publicstatic enqueue_unique_async_action()
public static function enqueue_unique_async_action(string $hook, array=array() $args, string=\'\' $group, array=array() $extra_groups): intEnqueue an async Action Scheduler job with atomic dedup when available. Parameter Type Default Description $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.
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): intSchedule a one-off Action Scheduler job with atomic dedup when available. Parameter Type Default Description $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.
publicstatic next_scheduled()
public static function next_scheduled(string $hook, array=array() $args)Probe when a WP-Cron event is next scheduled. Parameter Type Default Description $hookstring— Cron hook name. $argsarray=array()— Optional event args.
Return: int|false — Timestamp of the next run, or false when unscheduled/unavailable.
publicstatic schedule_recurring_event()
public static function schedule_recurring_event(string $hook, int $timestamp, string $recurrence, array=array() $args): boolSchedule a recurring WP-Cron event once (idempotent). Parameter Type Default Description $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.
publicstatic schedule_single_event()
public static function schedule_single_event(int $timestamp, string $hook, array=array() $args): boolSchedule a one-off WP-Cron event. Parameter Type Default Description $timestampint— When the event will run. $hookstring— Cron hook name. $argsarray=array()— Optional event args.
Return: bool — True on schedule, false when unavailable/failed.
publicstatic is_stampede_guard_enabled()
public static function is_stampede_guard_enabled(): boolWhether the stampede guard is enabled.
Return: bool — True when coalescing is active.
publicstatic stampede_lock_ttl()
public static function stampede_lock_ttl(): intEffective stampede lock TTL in seconds, clamped to 2-5s.
Return: int — Lock TTL clamped to 2-5 seconds.
publicstatic generate_stampede_owner()
public static function generate_stampede_owner(): stringGenerate a unique stampede lock owner token.
Return: string — Unique owner token (never empty).
publicstatic acquire_stampede_lock()
public static function acquire_stampede_lock(string $lock_key, string $owner, int=5 $ttl, string=\'wppo\' $group): boolAtomically acquire a named stampede lock. Parameter Type Default Description $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.
publicstatic release_stampede_lock()
public static function release_stampede_lock(string $lock_key, string $owner, string=\'wppo\' $group): voidRelease a stampede lock only when this worker still owns it. Parameter Type Default Description $lock_keystring— Blog-aware lock key. $ownerstring— Owner token that acquired the lock. $groupstring=\'wppo\'— Object-cache group for the lock.
Return: void.
Hooks
Hooks referenced in includes/Scheduler/class-scheduler.php: Hook Type Line Notes wppo_stampede_guard_enabledfilter 457 @param ×1 wppo_stampede_lock_ttlfilter 488 @param ×1