filter->getCollection($this->collectionFactory->create()); $deleted = 0; $skipped = 0; foreach ($collection as $task) { if ($task->getData('status') === 'processing') { $skipped++; continue; } $task->delete(); $deleted++; } $this->messageManager->addSuccessMessage(__('%1 queue task(s) deleted.', $deleted)); if ($skipped > 0) { $this->messageManager->addWarningMessage(__('%1 processing task(s) were not deleted.', $skipped)); } return $this->resultRedirectFactory->create()->setPath('*/*/'); } }