From ea82fad08b4d89d04b03750b02fcd26623cef824 Mon Sep 17 00:00:00 2001 From: Dharmesh Patel Date: Thu, 10 Oct 2024 17:53:51 +0530 Subject: [PATCH] Fix in progress background process status. --- includes/Classifai/TermCleanupScheduler.php | 31 ++++++++++----------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/includes/Classifai/TermCleanupScheduler.php b/includes/Classifai/TermCleanupScheduler.php index b8e4c5a48..ab2bbbb1a 100644 --- a/includes/Classifai/TermCleanupScheduler.php +++ b/includes/Classifai/TermCleanupScheduler.php @@ -159,20 +159,11 @@ public function unschedule() { * @return bool */ public function in_progress(): bool { - if ( ! class_exists( 'ActionScheduler_Store' ) ) { - return false; + if ( function_exists( 'as_has_scheduled_action' ) ) { + return as_has_scheduled_action( $this->job_name ); } - $store = ActionScheduler_Store::instance(); - - $action_id = $store->find_action( - $this->job_name, - array( - 'status' => ActionScheduler_Store::STATUS_PENDING, - ) - ); - - return ! empty( $action_id ); + return false; } /** @@ -187,19 +178,27 @@ public function get_args() { $store = ActionScheduler_Store::instance(); - $action_id = $store->find_action( + $running_action_id = $store->find_action( $this->job_name, array( 'status' => ActionScheduler_Store::STATUS_PENDING, ) ); - if ( empty( $action_id ) ) { + $pending_action_id = $store->find_action( + $this->job_name, + array( + 'status' => ActionScheduler_Store::STATUS_RUNNING, + ) + ); + + if ( empty( $running_action_id ) && empty( $pending_action_id ) ) { return false; } - $action = $store->fetch_action( $action_id ); - $args = $action->get_args(); + $action_id = ! empty( $running_action_id ) ? $running_action_id : $pending_action_id; + $action = $store->fetch_action( $action_id ); + $args = $action->get_args(); return $args; }