Properties

$cleaner

$cleaner : \ActionScheduler_QueueCleaner

ActionScheduler_QueueCleaner instance.

Type

normal

$monitor

$monitor : \ActionScheduler_FatalErrorMonitor

ActionScheduler_FatalErrorMonitor instance.

Type

normal

$store

$store : \ActionScheduler_Store

ActionScheduler_Store instance.

Type

normal

$actions

$actions : array

Claimed actions.

Type

normal

$claim

$claim : \ActionScheduler_ActionClaim

ActionScheduler_ActionClaim instance.

Type

normal

$progress_bar

$progress_bar : \cli\progress\Bar

Progress bar instance.

Type

\cli\progress\Bar

$created_time

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

Type

normal

Methods

__construct()

__construct(\ActionScheduler_Store|null  $store = null, \ActionScheduler_FatalErrorMonitor|null  $monitor = null, \ActionScheduler_QueueCleaner|null  $cleaner = null) : mixed

ActionScheduler_WPCLI_QueueRunner constructor.

Parameters

\ActionScheduler_Store|null $store

Store object.

\ActionScheduler_FatalErrorMonitor|null $monitor

Monitor object.

\ActionScheduler_QueueCleaner|null $cleaner

Cleaner object.

Throws

\Exception

When this is not run within WP CLI.

Returns

mixed

process_action()

process_action(int  $action_id, string  $context = '') : mixed

Process an individual action.

Parameters

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.

Throws

\Exception

When error running action.

Returns

mixed

get_allowed_concurrent_batches()

get_allowed_concurrent_batches() : int

Get the number of concurrent batches a runner allows.

Returns

int

has_maximum_concurrent_batches()

has_maximum_concurrent_batches() : bool

Check if the number of allowed concurrent batches is met or exceeded.

Returns

bool

run()

run(string  $context = 'WP CLI') : int

Process actions in the queue.

Parameters

string $context

Optional runner context. Default 'WP CLI'.

Returns

int —

The number of actions processed.

setup()

setup(int  $batch_size, array  $hooks = array(), string  $group = '', bool  $force = false) : int

Set up the Queue before processing.

Parameters

int $batch_size

The batch size to process.

array $hooks

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

string $group

The group of actions to claim with this batch.

bool $force

Whether to force running even with too many concurrent processes.

Throws

\WP_CLI\ExitException

When there are too many concurrent batches.

Returns

int —

The number of actions that will be run.

before_execute()

before_execute(int  $action_id) : mixed

Handle WP CLI message when the action is starting.

Parameters

int $action_id

Action ID.

Returns

mixed

after_execute()

after_execute(int  $action_id, null|\ActionScheduler_Action  $action = null) : mixed

Handle WP CLI message when the action has completed.

Parameters

int $action_id

ActionID.

null|\ActionScheduler_Action $action

The instance of the action. Default to null for backward compatibility.

Returns

mixed

action_failed()

action_failed(int  $action_id, \Exception  $exception) : mixed

Handle WP CLI message when the action has failed.

Parameters

int $action_id

Action ID.

\Exception $exception

Exception.

Throws

\WP_CLI\ExitException

With failure message.

Returns

mixed

schedule_next_instance()

schedule_next_instance(\ActionScheduler_Action  $action, int  $action_id) : mixed

Schedule the next instance of the action if necessary.

Parameters

\ActionScheduler_Action $action

Action.

int $action_id

Action ID.

Returns

mixed

run_cleanup()

run_cleanup() : mixed

Run the queue cleaner.

Returns

mixed

get_time_limit()

get_time_limit() : int

Get the maximum number of seconds a batch can run for.

Returns

int —

The number of seconds.

get_execution_time()

get_execution_time() : int

Get the number of seconds the process has been running.

Returns

int —

The number of seconds.

time_likely_to_be_exceeded()

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.

Parameters

int $processed_actions

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

Returns

bool

get_memory_limit()

get_memory_limit() : int

Get memory limit

Based on WP_Background_Process::get_memory_limit()

Returns

int

memory_exceeded()

memory_exceeded() : bool

Memory exceeded

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

Based on WP_Background_Process::memory_exceeded()

Returns

bool

batch_limits_exceeded()

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()

Parameters

int $processed_actions

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

Returns

bool

get_maximum_execution_time()

get_maximum_execution_time() : int

Get the maximum number of seconds a batch can run for.

Returns

int —

The number of seconds.

add_hooks()

add_hooks() : mixed

Add our hooks to the appropriate actions.

Returns

mixed

setup_progress_bar()

setup_progress_bar() : mixed

Set up the WP CLI progress bar.

Returns

mixed

stop_the_insanity()

stop_the_insanity(int  $sleep_time) : mixed

Sleep and help avoid hitting memory limit

Parameters

int $sleep_time

Amount of seconds to sleep.

Returns

mixed

maybe_stop_the_insanity()

maybe_stop_the_insanity() : mixed

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

Returns

mixed

handle_action_error()

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.

Parameters

int $action_id

Action ID.

\Exception $e

Exception instance.

string $context

Execution context.

bool $valid_action

If the action is valid.

recurring_action_is_consistently_failing()

recurring_action_is_consistently_failing(\ActionScheduler_Action  $action, int  $action_id) : bool

Determine if the specified recurring action has been consistently failing.

Parameters

\ActionScheduler_Action $action

The recurring action to be rescheduled.

int $action_id

The ID of the recurring action.

Returns

bool