• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
WooCommerce a2z

WooCommerce a2z

WooCommerce

  • Home
  • Plugins
  • Blocks
  • Shortcodes
  • APIs
  • Classes
  • Files
  • Hooks
  • Sitemap
  • Blog
Home / APIs / ActionScheduler_WPCLI_Scheduler_command::run() – Run the Action Scheduler

You appear to be a bot. Output may be restricted

Description

Run the Action Scheduler

OPTIONS

[–batch-size=<size>] : The maximum number of actions to run. Defaults to 100. [–batches=<size>] : Limit execution to a number of batches. Defaults to 0, meaning batches will continue being executed until all actions are complete. [–cleanup-batch-size=<size>] : The maximum number of actions to clean up. Defaults to the value of –batch-size. [–hooks=<hooks>] : Only run actions with the specified hook. Omitting this option runs actions with any hook. Define multiple hooks as a comma separated string (without spaces), e.g. --hooks=hook_one,hook_two,hook_three [–group=<group>] : Only run actions from the specified group. Omitting this option runs actions from all groups. [–free-memory-on=<count>] : The number of actions to process between freeing memory. 0 disables freeing memory. Default 50. [–pause=<seconds>] : The number of seconds to pause when freeing memory. Default no pause. [–force] : Whether to force execution despite the maximum number of concurrent processes being exceeded.

Usage

ActionScheduler_WPCLI_Scheduler_command::run( $args, $assoc_args );

Parameters

$args
( array ) required – Positional arguments.
$assoc_args
( array ) required – Keyed arguments.

Returns

void

Source

File name: woocommerce/packages/action-scheduler/classes/WP_CLI/ActionScheduler_WPCLI_Scheduler_command.php


Lines:

1 to 46 of 46
  public function run( $args, $assoc_args ) {
    // Handle passed arguments.
    $batch   = absint( \WP_CLI\Utils\get_flag_value( $assoc_args, 'batch-size', 100 ) );
    $batches = absint( \WP_CLI\Utils\get_flag_value( $assoc_args, 'batches', 0 ) );
    $clean   = absint( \WP_CLI\Utils\get_flag_value( $assoc_args, 'cleanup-batch-size', $batch ) );
    $hooks   = explode( ',', WP_CLI\Utils\get_flag_value( $assoc_args, 'hooks', '' ) );
    $hooks   = array_filter( array_map( 'trim', $hooks ) );
    $group   = \WP_CLI\Utils\get_flag_value( $assoc_args, 'group', '' );
    $free_on = \WP_CLI\Utils\get_flag_value( $assoc_args, 'free-memory-on', 50 );
    $sleep   = \WP_CLI\Utils\get_flag_value( $assoc_args, 'pause', 0 );
    $force   = \WP_CLI\Utils\get_flag_value( $assoc_args, 'force', false );

    ActionScheduler_DataController::set_free_ticks( $free_on );
    ActionScheduler_DataController::set_sleep_time( $sleep );

    $batches_completed = 0;
    $actions_completed = 0;
    $unlimited         = $batches === 0;

    try {
      // Custom queue cleaner instance.
      $cleaner = new ActionScheduler_QueueCleaner( null, $clean );

      // Get the queue runner instance
      $runner = new ActionScheduler_WPCLI_QueueRunner( null, null, $cleaner );

      // Determine how many tasks will be run in the first batch.
      $total = $runner->setup( $batch, $hooks, $group, $force );

      // Run actions for as long as possible.
      while ( $total > 0 ) {
        $this->print_total_actions( $total );
        $actions_completed += $runner->run();
        $batches_completed++;

        // Maybe set up tasks for the next batch.
        $total = ( $unlimited || $batches_completed < $batches ) ? $runner->setup( $batch, $hooks, $group, $force ) : 0;
      }
    } catch ( Exception $e ) {
      $this->print_error( $e );
    }

    $this->print_total_batches( $batches_completed );
    $this->print_success( $actions_completed );
  }
 

 View on GitHub View on Trac

Published: 8th February 2020 | Last updated: 6th May 2020

Primary Sidebar

Information

Function name: ActionScheduler_WPCLI_Scheduler_command::run
Class ref: ActionScheduler_WPCLI_Scheduler_command
Plugin ref: WooCommerce
Version: 5.1.0
Sourcefile: packages/action-scheduler/classes/WP_CLI/ActionScheduler_WPCLI_Scheduler_command.php
File ref: packages/action-scheduler/classes/WP_CLI/ActionScheduler_WPCLI_Scheduler_command.php
Deprecated?: No
API Letters: A,C,R,S,W

Footer

WooCommerce a2z
WooCommerce a2z
WooCommerce
WordPress 5.7.1
WordPress a2z
WordPress core a2z
Genesis Theme Framework a2z
Jetpack a2z
WordPress develop tests
Easy Digital Downloads a2z
WooCommerce a2z
Yoast SEO a2z
WordPress Blocks

Site:  woocommerce.wp-a2z.org
© Copyright WooCommerce a2z 2014-2021. All rights reserved.


Website designed and developed by Herb Miller
Proudly powered by WordPress and oik plugins

  • Home
  • Blog
  • Sitemap
  • Sites