Menu

## ActionScheduler_WPCLI_QueueRunner extends ActionScheduler_Abstract_QueueRunner
in package

ActionScheduler_WPCLI_QueueRunner.php : 8

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

#### $actions

ActionScheduler_WPCLI_QueueRunner.php : 11
`protected array<string|int, mixed> $actions`

#### $claim

ActionScheduler_WPCLI_QueueRunner.php : 14
`protected ActionScheduler_ActionClaim $claim`

#### $cleaner

ActionScheduler_Abstract_QueueRunner.php : 9
`protected ActionScheduler_QueueCleaner $cleaner`

#### $monitor

ActionScheduler_Abstract_QueueRunner.php : 12
`protected ActionScheduler_FatalErrorMonitor $monitor`

#### $progress_bar

ActionScheduler_WPCLI_QueueRunner.php : 17
`protected Bar $progress_bar`

#### $store

ActionScheduler_Abstract_QueueRunner.php : 15
`protected ActionScheduler_Store $store`

#### $created_time

ActionScheduler_Abstract_QueueRunner.php : 25

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.php : 28

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

ActionScheduler_WPCLI_QueueRunner.php : 164

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 —

#### after_execute()

ActionScheduler_WPCLI_QueueRunner.php : 146

Handle WP CLI message when the action has completed.

`public after_execute(int $action_id[, null|ActionScheduler_Action $action = null ]) : mixed`

##### Parameters

$action_id : int
$action : null|ActionScheduler_Action = null

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

##### Tags

author

  Jeremy Pry

##### Return values

mixed —

#### before_execute()

ActionScheduler_WPCLI_QueueRunner.php : 133

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

ActionScheduler_Abstract_QueueRunner.php : 100

Get the number of concurrent batches a runner allows.

`public get_allowed_concurrent_batches() : int`

##### Return values

int —

#### process_action()

ActionScheduler_Abstract_QueueRunner.php : 48

Process an individual action.

`public process_action(int $action_id) : mixed`

##### Parameters

$action_id : int

  The action ID to process.

##### Return values

mixed —

#### run()

ActionScheduler_WPCLI_QueueRunner.php : 103

Process actions in the queue.

`public run() : int`

##### Tags

author

  Jeremy Pry

##### Return values

int —

The number of actions processed.

#### setup()

ActionScheduler_WPCLI_QueueRunner.php : 50

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.

#### add_hooks()

ActionScheduler_WPCLI_QueueRunner.php : 78

Add our hooks to the appropriate actions.

`protected add_hooks() : mixed`

##### Tags

author

  Jeremy Pry

##### Return values

mixed —

#### batch_limits_exceeded()

ActionScheduler_Abstract_QueueRunner.php : 208

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

ActionScheduler_Abstract_QueueRunner.php : 127

Get the number of seconds the process has been running.

`protected get_execution_time() : int`

##### Return values

int —

The number of seconds.

#### get_maximum_execution_time()

ActionScheduler_Abstract_QueueRunner_Deprecated.php : 14

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

`protected get_maximum_execution_time() : int`

##### Tags

deprecated
  2.1.1

##### Return values

int —

The number of seconds.

#### get_memory_limit()

ActionScheduler_Abstract_QueueRunner.php : 166

Get memory limit

`protected get_memory_limit() : int`

Based on WP_Background_Process::get_memory_limit()

##### Return values

int —

#### get_time_limit()

ActionScheduler_Abstract_QueueRunner.php : 109

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

`protected get_time_limit() : int`

##### Return values

int —

The number of seconds.

#### maybe_stop_the_insanity()

ActionScheduler_WPCLI_QueueRunner.php : 210

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

`protected maybe_stop_the_insanity() : mixed`

##### Return values

mixed —

#### memory_exceeded()

ActionScheduler_Abstract_QueueRunner.php : 190

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 —

#### run_cleanup()

ActionScheduler_Abstract_QueueRunner.php : 91

Run the queue cleaner.

`protected run_cleanup() : mixed`

##### Tags

author

  Jeremy Pry

##### Return values

mixed —

#### schedule_next_instance()

ActionScheduler_Abstract_QueueRunner.php : 77

Schedule the next instance of the action if necessary.

`protected schedule_next_instance(ActionScheduler_Action $action) : mixed`

##### Parameters

$action : ActionScheduler_Action

##### Return values

mixed —

#### setup_progress_bar()

ActionScheduler_WPCLI_QueueRunner.php : 89

Set up the WP CLI progress bar.

`protected setup_progress_bar() : mixed`

##### Tags

author

  Jeremy Pry

##### Return values

mixed —

#### stop_the_insanity()

ActionScheduler_WPCLI_QueueRunner.php : 177

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

ActionScheduler_Abstract_QueueRunner.php : 148

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