Skip to content

Commit

Permalink
Fix in progress background process status.
Browse files Browse the repository at this point in the history
  • Loading branch information
iamdharmesh committed Oct 10, 2024
1 parent 67bf608 commit ea82fad
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions includes/Classifai/TermCleanupScheduler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -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;
}
Expand Down

0 comments on commit ea82fad

Please sign in to comment.