Automattic\WooCommerce\Admin\API
AnalyticsImports::is_import_in_progress_or_due
Check if a batch import is currently in progress or due to run soon.
Method of the class: AnalyticsImports{}
No Hooks.
Returns
true|false. True if a batch import is in progress or scheduled to run within the next minute, false otherwise.
Usage
// private - for code of main (parent) class only $result = $this->is_import_in_progress_or_due();
AnalyticsImports::is_import_in_progress_or_due() AnalyticsImports::is import in progress or due code WC 10.5.0
private function is_import_in_progress_or_due() {
$hook = OrdersScheduler::get_action( OrdersScheduler::PROCESS_PENDING_ORDERS_BATCH_ACTION );
if ( ! is_string( $hook ) ) {
return false;
}
// Check for actions with 'in-progress' status.
$in_progress_actions = WC()->queue()->search(
array(
'hook' => $hook,
'status' => 'in-progress',
'per_page' => 1,
),
'ids'
);
if ( ! empty( $in_progress_actions ) ) {
return true;
}
// Check if the next scheduled import is due within 1 minute.
$next_scheduled = WC()->queue()->get_next( $hook, array(), (string) OrdersScheduler::$group );
if ( $next_scheduled ) {
$time_until_next = $next_scheduled->getTimestamp() - time();
// Consider it "due" if it's scheduled to run within the next 60 seconds.
if ( $time_until_next <= MINUTE_IN_SECONDS ) {
return true;
}
}
return false;
}