ActionScheduler_WPCLI_QueueRunner::setup
Set up the Queue before processing.
Method of the class: ActionScheduler_WPCLI_QueueRunner{}
No Hooks.
Returns
Int. The number of actions that will be run.
Usage
$ActionScheduler_WPCLI_QueueRunner = new ActionScheduler_WPCLI_QueueRunner(); $ActionScheduler_WPCLI_QueueRunner->setup( $batch_size, $hooks, $group, $force );
- $batch_size(int) (required)
- The batch size to process.
- $hooks(array)
- The hooks being used to filter the actions claimed in this batch.
Default:array() - $group(string)
- The group of actions to claim with this batch.
Default:'' - $force(true|false)
- Whether to force running even with too many concurrent processes.
Default:false
ActionScheduler_WPCLI_QueueRunner::setup() ActionScheduler WPCLI QueueRunner::setup code WC 11.0.1
public function setup( $batch_size, $hooks = array(), $group = '', $force = false ) {
$cleanup_time_limit = 10 * $this->get_time_limit();
// Backward compatibility: If the action cleaner is standard, cleaning will be performed as an action to improve throughput
// and enable daily runs. If not, cleaning will occur explicitly before processing actions to ensure backward compatibility.
if ( $this->is_custom_cleaner ) {
// Execute complete cleanup cycle, as in this logical branch deletion IS NOT executed via a separate action.
$this->cleaner->clean( $cleanup_time_limit );
} else {
// Execute partial cleanup cycle, as in this logical branch deletion IS executed via a separate action.
$this->cleaner->reset_timeouts( $cleanup_time_limit );
$this->cleaner->mark_failures( $cleanup_time_limit );
}
$this->add_hooks();
// Check to make sure there aren't too many concurrent processes running.
if ( $this->has_maximum_concurrent_batches() ) {
if ( $force ) {
WP_CLI::warning( __( 'There are too many concurrent batches, but the run is forced to continue.', 'woocommerce' ) );
} else {
WP_CLI::error( __( 'There are too many concurrent batches.', 'woocommerce' ) );
}
}
// Stake a claim and store it.
$this->claim = $this->store->stake_claim( $batch_size, null, $hooks, $group );
$this->monitor->attach( $this->claim );
$this->actions = $this->claim->get_actions();
return count( $this->actions );
}