Skip to content

Commit

Permalink
CI-5006 move around some queue functionality so tasks get removed pro…
Browse files Browse the repository at this point in the history
…perly
  • Loading branch information
Ryan Kanner committed Apr 4, 2018
1 parent 28b9314 commit c93ac92
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/Processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,22 +234,21 @@ private function remove_tasks_from_queue( $successful_tasks, $failed_tasks ) {
if ( ! empty( $tasks ) && is_array( $tasks ) ) {
foreach ( $tasks as $task ) {

// Get the queues attached to the task
$queues_attached = get_the_terms( $task, 'task-queue' );

// If the task was successful, and only in the one queue, remove it.
if ( in_array( $task, $successful_tasks, true ) && ( ! empty( $queues_attached ) && 1 === count( $queues_attached ) ) ) {
wp_delete_post( $task, true );
} else {
// Remove the task from the current queue
wp_remove_object_terms( $task, $this->queue_id, 'task-queue' );
}
wp_remove_object_terms( $task, $this->queue_id, 'task-queue' );

if ( in_array( $task, $tasks_out_of_retries, true ) ) {
// If the task failed too many times, put it in the "failed" queue for safe keeping.
wp_set_object_terms( $task, $this->queue_name . '_' . $this->failed_queue, 'task-queue', true );
}

// Get the queues attached to the task
$queues_attached = get_the_terms( $task, 'task-queue' );

// If no queues are left on the task, delete it.
if ( false === $queues_attached ) {
wp_delete_post( $task, true );
}

}
}

Expand Down

0 comments on commit c93ac92

Please sign in to comment.