Documentation

ActionScheduler_WPCLI_QueueRunner extends ActionScheduler_Abstract_QueueRunner
in package

WP CLI Queue runner.

This class can only be called from within a WP CLI instance.

Table of Contents

$actions  : array<string|int, mixed>
$claim  : ActionScheduler_ActionClaim
$cleaner  : ActionScheduler_QueueCleaner
$monitor  : ActionScheduler_FatalErrorMonitor
$progress_bar  : Bar
$store  : ActionScheduler_Store
$created_time  : int
The created time.
__construct()  : mixed
ActionScheduler_WPCLI_QueueRunner constructor.
action_failed()  : mixed
Handle WP CLI message when the action has failed.
after_execute()  : mixed
Handle WP CLI message when the action has completed.
before_execute()  : mixed
Handle WP CLI message when the action is starting.
get_allowed_concurrent_batches()  : int
Get the number of concurrent batches a runner allows.
process_action()  : mixed
Process an individual action.
run()  : int
Process actions in the queue.
setup()  : int
Set up the Queue before processing.
add_hooks()  : mixed
Add our hooks to the appropriate actions.
batch_limits_exceeded()  : 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.
get_execution_time()  : int
Get the number of seconds the process has been running.
get_maximum_execution_time()  : int
Get the maximum number of seconds a batch can run for.
get_memory_limit()  : int
Get memory limit
get_time_limit()  : int
Get the maximum number of seconds a batch can run for.
maybe_stop_the_insanity()  : mixed
Maybe trigger the stop_the_insanity() method to free up memory.
memory_exceeded()  : bool
Memory exceeded
run_cleanup()  : mixed
Run the queue cleaner.
schedule_next_instance()  : mixed
Schedule the next instance of the action if necessary.
setup_progress_bar()  : mixed
Set up the WP CLI progress bar.
stop_the_insanity()  : mixed
Sleep and help avoid hitting memory limit
time_likely_to_be_exceeded()  : bool
Check if the host's max execution time is (likely) to be exceeded if processing more actions.

Properties

$created_time

The created time.

private int $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.

Methods

__construct()

ActionScheduler_WPCLI_QueueRunner constructor.

public __construct([ActionScheduler_Store $store = null ][, ActionScheduler_FatalErrorMonitor $monitor = null ][, ActionScheduler_QueueCleaner $cleaner = null ]) : mixed
Parameters
$store : ActionScheduler_Store = null
$monitor : ActionScheduler_FatalErrorMonitor = null
$cleaner : ActionScheduler_QueueCleaner = null
Tags
throws
Exception

When this is not run within WP CLI

Return values
mixed

action_failed()

Handle WP CLI message when the action has failed.

public action_failed(int $action_id, Exception $exception) : mixed
Parameters
$action_id : int
$exception : Exception
Tags
author

Jeremy Pry

throws
ExitException

With failure message.

Return values
mixed

before_execute()

Handle WP CLI message when the action is starting.

public before_execute( $action_id) : mixed
Parameters
$action_id :
Tags
author

Jeremy Pry

Return values
mixed

get_allowed_concurrent_batches()

Get the number of concurrent batches a runner allows.

public get_allowed_concurrent_batches() : int
Return values
int

process_action()

Process an individual action.

public process_action(int $action_id) : mixed
Parameters
$action_id : int

The action ID to process.

Return values
mixed

setup()

Set up the Queue before processing.

public setup(int $batch_size[, array<string|int, mixed> $hooks = array() ][, string $group = '' ][, bool $force = false ]) : int
Parameters
$batch_size : int

The batch size to process.

$hooks : array<string|int, mixed> = array()

The hooks being used to filter the actions claimed in this batch.

$group : string = ''

The group of actions to claim with this batch.

$force : bool = false

Whether to force running even with too many concurrent processes.

Tags
author

Jeremy Pry

throws
ExitException

When there are too many concurrent batches.

Return values
int

The number of actions that will be run.

batch_limits_exceeded()

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.

protected batch_limits_exceeded(int $processed_actions) : bool

Based on WC_Background_Process::batch_limits_exceeded()

Parameters
$processed_actions : int

The number of actions processed so far - used to determine the likelihood of exceeding the time limit if processing another action

Return values
bool

get_execution_time()

Get the number of seconds the process has been running.

protected get_execution_time() : int
Return values
int

The number of seconds.

maybe_stop_the_insanity()

Maybe trigger the stop_the_insanity() method to free up memory.

protected maybe_stop_the_insanity() : mixed
Return values
mixed

memory_exceeded()

Memory exceeded

protected memory_exceeded() : bool

Ensures the batch process never exceeds 90% of the maximum WordPress memory.

Based on WP_Background_Process::memory_exceeded()

Return values
bool

stop_the_insanity()

Sleep and help avoid hitting memory limit

protected stop_the_insanity(int $sleep_time) : mixed
Parameters
$sleep_time : int

Amount of seconds to sleep

Return values
mixed

time_likely_to_be_exceeded()

Check if the host's max execution time is (likely) to be exceeded if processing more actions.

protected time_likely_to_be_exceeded(int $processed_actions) : bool
Parameters
$processed_actions : int

The number of actions processed so far - used to determine the likelihood of exceeding the time limit if processing another action

Return values
bool

Search results