Merge pull request woocommerce/woocommerce-admin#1664 from woocommerce/add/action-scheduler-group

add action scheduler group
This commit is contained in:
Ron Rennick 2019-02-25 16:13:15 -04:00 committed by GitHub
commit 39226c8c2c
2 changed files with 14 additions and 5 deletions

View File

@ -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 );
}
}

View File

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