format(DateTimeUtil::SYSTEM_DATE_TIME_FORMAT); $nowShifted = $dt ->sub(new DateInterval('PT1H')) ->format(DateTimeUtil::SYSTEM_DATE_TIME_FORMAT); $maxPortionSize = $this->config->get('emailReminderPortionSize') ?? self::MAX_PORTION_SIZE; $collection = $this->entityManager ->getRDBRepository(Reminder::ENTITY_TYPE) ->where([ 'type' => Reminder::TYPE_EMAIL, 'remindAt<=' => $now, 'startAt>' => $nowShifted, ]) ->limit(0, $maxPortionSize) ->find(); if (is_countable($collection) && count($collection) === 0) { return; } $emailReminder = $this->injectableFactory->create(EmailReminder::class); foreach ($collection as $entity) { try { $emailReminder->send($entity); } catch (Throwable $e) { $this->log->error("Email reminder '{$entity->getId()}': " . $e->getMessage()); } $this->entityManager ->getRDBRepository(Reminder::ENTITY_TYPE) ->deleteFromDb($entity->getId()); } } }