Add method for cleaning up orphaned sending tasks

[MAILPOET-1587]
This commit is contained in:
Rostislav Wolny
2024-08-01 10:10:49 +02:00
committed by Aschepikov
parent 08ffe6e3cf
commit b68e6b7639
2 changed files with 37 additions and 6 deletions

View File

@@ -10,11 +10,11 @@ use MailPoet\Test\DataFactories\SendingQueue;
class DataInconsistencyRepositoryTest extends \MailPoetTest {
private DataInconsistencyRepository $repository;
public function _before() {
public function _before(): void {
$this->repository = $this->diContainer->get(DataInconsistencyRepository::class);
}
public function testItFetchesOrphanedSendingTasksCount() {
public function testItFetchesOrphanedSendingTasksCount(): void {
$orphanedSendingTasksCount = $this->repository->getOrphanedSendingTasksCount();
verify($orphanedSendingTasksCount)->equals(0);
@@ -30,4 +30,15 @@ class DataInconsistencyRepositoryTest extends \MailPoetTest {
$orphanedSendingTasksCount = $this->repository->getOrphanedSendingTasksCount();
verify($orphanedSendingTasksCount)->equals(2);
}
public function testItCleansUpOrphanedSendingTasks(): void {
(new ScheduledTask())->create(SendingQueueWorker::TASK_TYPE, ScheduledTaskEntity::STATUS_SCHEDULED);
(new ScheduledTask())->create(SendingQueueWorker::TASK_TYPE, null);
$orphanedSendingTasksCount = $this->repository->getOrphanedSendingTasksCount();
verify($orphanedSendingTasksCount)->equals(2);
$this->repository->cleanupOrphanedSendingTasks();
$orphanedSendingTasksCount = $this->repository->getOrphanedSendingTasksCount();
verify($orphanedSendingTasksCount)->equals(0);
}
}