From 4cad5833326755f145c18ce189373c56f446f587 Mon Sep 17 00:00:00 2001 From: Ron Rennick Date: Thu, 21 Feb 2019 15:44:35 -0400 Subject: [PATCH 1/2] add action scheduler group --- .../includes/class-wc-admin-reports-sync.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/plugins/woocommerce-admin/includes/class-wc-admin-reports-sync.php b/plugins/woocommerce-admin/includes/class-wc-admin-reports-sync.php index c0aafe9a130..cd2f5e3e39e 100644 --- a/plugins/woocommerce-admin/includes/class-wc-admin-reports-sync.php +++ b/plugins/woocommerce-admin/includes/class-wc-admin-reports-sync.php @@ -41,6 +41,11 @@ class WC_Admin_Reports_Sync { */ const SINGLE_ORDER_ACTION = 'wc-admin_process_order'; + /** + * Action hook for processing a batch of orders. + */ + const QUEUE_GROUP = 'wc-admin-data'; + /** * Queue instance. * @@ -145,6 +150,7 @@ class WC_Admin_Reports_Sync { 'per_page' => 1, 'claimed' => false, 'search' => "[{$order_id}]", + 'group' => self::QUEUE_GROUP, ) ); @@ -308,13 +314,14 @@ class WC_Admin_Reports_Sync { self::queue()->schedule_single( $action_timestamp, self::QUEUE_BATCH_ACTION, - array( $batch_start, $batch_end, $single_batch_action ) + array( $batch_start, $batch_end, $single_batch_action ), + self::QUEUE_GROUP ); } } else { // Otherwise, queue the single batches. for ( $i = $range_start; $i <= $range_end; $i++ ) { - self::queue()->schedule_single( $action_timestamp, $single_batch_action, array( $i ) ); + self::queue()->schedule_single( $action_timestamp, $single_batch_action, array( $i ), self::QUEUE_GROUP ); } } } @@ -335,6 +342,7 @@ class WC_Admin_Reports_Sync { 'per_page' => 1, 'claimed' => false, 'search' => $prerequisite_action, // search is used instead of hook to find queued batch creation. + 'group' => self::QUEUE_GROUP, ) ); @@ -357,10 +365,11 @@ class WC_Admin_Reports_Sync { self::queue()->schedule_single( $next_job_schedule->getTimestamp() + 5, self::QUEUE_DEPEDENT_ACTION, - array( $action, $action_args, $prerequisite_action ) + array( $action, $action_args, $prerequisite_action ), + self::QUEUE_GROUP ); } else { - self::queue()->schedule_single( time() + 5, $action, $action_args ); + self::queue()->schedule_single( time() + 5, $action, $action_args, self::QUEUE_GROUP ); } } From 6969f841fa2ad1266bff1f0a269b529bb7c030d2 Mon Sep 17 00:00:00 2001 From: Ron Rennick Date: Mon, 25 Feb 2019 09:34:59 -0400 Subject: [PATCH 2/2] update unit tests for batch group --- plugins/woocommerce-admin/tests/batch-queue.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/woocommerce-admin/tests/batch-queue.php b/plugins/woocommerce-admin/tests/batch-queue.php index 480c92018e6..180e54e9989 100644 --- a/plugins/woocommerce-admin/tests/batch-queue.php +++ b/plugins/woocommerce-admin/tests/batch-queue.php @@ -134,7 +134,7 @@ class WC_Tests_Reports_Regenerate_Batching extends WC_REST_Unit_Test_Case { WC_Admin_Reports_Sync::set_queue( null ); // insert a blocking job. - WC_Admin_Reports_Sync::queue()->schedule_single( time(), 'blocking_job', array( 'stuff' ) ); + WC_Admin_Reports_Sync::queue()->schedule_single( time(), 'blocking_job', array( 'stuff' ), WC_Admin_Reports_Sync::QUEUE_GROUP ); // queue an action that depends on blocking job. WC_Admin_Reports_Sync::queue_dependent_action( 'dependent_action', array(), 'blocking_job' ); // verify that the action was properly blocked.