From c36c9d23916859255b8ce3417d21d4899129f7d3 Mon Sep 17 00:00:00 2001 From: "Ian M. Jones" Date: Tue, 18 Jul 2023 10:25:40 +0100 Subject: [PATCH] Ensure task processing cleanly pauses or cancels as soon as possible --- classes/wp-background-process.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/classes/wp-background-process.php b/classes/wp-background-process.php index 82a8e63..d10351a 100644 --- a/classes/wp-background-process.php +++ b/classes/wp-background-process.php @@ -527,8 +527,8 @@ protected function handle() { // Let the server breathe a little. sleep( $throttle_seconds ); - if ( $this->time_exceeded() || $this->memory_exceeded() ) { - // Batch limits reached. + // Batch limits reached, or pause or cancel request. + if ( $this->time_exceeded() || $this->memory_exceeded() || $this->is_paused() || $this->is_cancelled() ) { break; } } @@ -537,7 +537,7 @@ protected function handle() { if ( empty( $batch->data ) ) { $this->delete( $batch->key ); } - } while ( ! $this->time_exceeded() && ! $this->memory_exceeded() && ! $this->is_queue_empty() ); + } while ( ! $this->time_exceeded() && ! $this->memory_exceeded() && ! $this->is_queue_empty() && ! $this->is_paused() && ! $this->is_cancelled() ); $this->unlock_process();