WP_CRON_HOOK
WP_CRON_HOOK = 'action_scheduler_run_queue'
Class ActionScheduler_QueueRunner
$cleaner : \ActionScheduler_QueueCleaner
ActionScheduler_QueueCleaner instance.
$monitor : \ActionScheduler_FatalErrorMonitor
ActionScheduler_FatalErrorMonitor instance.
$store : \ActionScheduler_Store
ActionScheduler_Store instance.
$async_request : \ActionScheduler_AsyncRequest_QueueRunner
ActionScheduler_AsyncRequest_QueueRunner instance.
$created_time : int
The created time.
Represents when the queue runner was constructed and used when calculating how long a PHP request has been running. For this reason it should be as close as possible to the PHP request start time.
$runner : \ActionScheduler_QueueRunner
ActionScheduler_QueueRunner instance.
$processed_actions_count : int
Number of processed actions.
__construct(\ActionScheduler_Store|null $store = null, \ActionScheduler_FatalErrorMonitor|null $monitor = null, \ActionScheduler_QueueCleaner|null $cleaner = null, \ActionScheduler_AsyncRequest_QueueRunner|null $async_request = null) : mixed
ActionScheduler_QueueRunner constructor.
\ActionScheduler_Store|null | $store | Store object. |
\ActionScheduler_FatalErrorMonitor|null | $monitor | Monitor object. |
\ActionScheduler_QueueCleaner|null | $cleaner | Cleaner object. |
\ActionScheduler_AsyncRequest_QueueRunner|null | $async_request | Async request runner object. |
process_action(int $action_id, string $context = '') : mixed
Process an individual action.
int | $action_id | The action ID to process. |
string | $context | Optional identifier for the context in which this action is being processed, e.g. 'WP CLI' or 'WP Cron' Generally, this should be capitalised and not localised as it's a proper noun. |
When error running action.
run(string $context = 'WP Cron') : int
Process actions in the queue. Attached to self::WP_CRON_HOOK i.e. 'action_scheduler_run_queue'
The $context param of this method defaults to 'WP Cron', because prior to Action Scheduler 3.0.0 that was the only context in which this method was run, and the self::WP_CRON_HOOK hook had no context passed along with it. New code calling this method directly, or by triggering the self::WP_CRON_HOOK, should set a context as the first parameter. For an example of this, refer to the code seen in
string | $context | Optional identifier for the context in which this action is being processed, e.g. 'WP CLI' or 'WP Cron' Generally, this should be capitalised and not localised as it's a proper noun. |
The number of actions processed.
maybe_dispatch_async_request() : mixed
Check if we should dispatch an async request to process actions.
This method is attached to 'shutdown', so is called frequently. To avoid slowing down the site, it mitigates the work performed in each request by:
The order of these checks is important, because they run from a check on a value:
If all of these conditions are met, then we request an async runner check whether it should dispatch a request to process pending actions.
time_likely_to_be_exceeded(int $processed_actions) : bool
Check if the host's max execution time is (likely) to be exceeded if processing more actions.
int | $processed_actions | The number of actions processed so far - used to determine the likelihood of exceeding the time limit if processing another action. |
batch_limits_exceeded(int $processed_actions) : bool
See if the batch limits have been exceeded, which is when memory usage is almost at the maximum limit, or the time to process more actions will exceed the max time limit.
Based on WC_Background_Process::batch_limits_exceeded()
int | $processed_actions | The number of actions processed so far - used to determine the likelihood of exceeding the time limit if processing another action. |
do_batch(int $size = 100, string $context = '') : int
Process a batch of actions pending in the queue.
Actions are processed by claiming a set of pending actions then processing each one until either the batch size is completed, or memory or time limits are reached, defined by @see $this->batch_limits_exceeded().
int | $size | The maximum number of actions to process in the batch. |
string | $context | Optional identifier for the context in which this action is being processed, e.g. 'WP CLI' or 'WP Cron' Generally, this should be capitalised and not localised as it's a proper noun. |
The number of actions processed.
None found |
clear_caches() : mixed
Flush the cache if possible (intended for use after a batch of actions has been processed).
This is useful because running large batches can eat up memory and because invalid data can accrue in the runtime cache, which may lead to unexpected results.
None found |
handle_action_error(int $action_id, \Exception $e, string $context, bool $valid_action) : void
Marks actions as either having failed execution or failed validation, as appropriate.
int | $action_id | Action ID. |
\Exception | $e | Exception instance. |
string | $context | Execution context. |
bool | $valid_action | If the action is valid. |
None found |
recurring_action_is_consistently_failing(\ActionScheduler_Action $action, int $action_id) : bool
Determine if the specified recurring action has been consistently failing.
\ActionScheduler_Action | $action | The recurring action to be rescheduled. |
int | $action_id | The ID of the recurring action. |
None found |