Cleanup orphaned stats notification tasks

[MAILPOET-3015]
This commit is contained in:
Rostislav Wolny
2020-06-25 15:54:40 +02:00
committed by Veljko V
parent aaf38a6f96
commit 3621a02b71
2 changed files with 12 additions and 0 deletions

View File

@ -55,4 +55,14 @@ class StatsNotificationsRepository extends Repository {
}
return $query->getQuery()->getResult();
}
public function deleteOrphanedScheduledTasks() {
$scheduledTasksTable = $this->entityManager->getClassMetadata(ScheduledTaskEntity::class)->getTableName();
$statsNotificationsTable = $this->entityManager->getClassMetadata(StatsNotificationEntity::class)->getTableName();
$this->entityManager->getConnection()->executeUpdate("
DELETE st FROM $scheduledTasksTable st
LEFT JOIN $statsNotificationsTable sn ON sn.task_id = st.id
WHERE sn.id IS NULL AND st.type = :taskType;
", ['taskType' => Worker::TASK_TYPE]);
}
}

View File

@ -89,6 +89,8 @@ class Worker {
public function process($timer = false) {
$timer = $timer ?: microtime(true);
$settings = $this->settings->get(self::SETTINGS_KEY);
// Cleanup potential orphaned task created due bug MAILPOET-3015
$this->repository->deleteOrphanedScheduledTasks();
foreach ($this->repository->findScheduled(Sending::RESULT_BATCH_SIZE) as $statsNotificationEntity) {
try {
$extraParams = [