1
0
Fork 0
mirror of synced 2024-07-12 18:05:55 +12:00

Merge remote-tracking branch 'origin/feat-message-scheduling' into feat-maintenance-delete-expired-targets

This commit is contained in:
Jake Barnby 2024-01-17 15:02:14 +13:00
commit ad40e0a3c5
No known key found for this signature in database
GPG key ID: C437A8CC85B96E9C
2 changed files with 16 additions and 8 deletions

View file

@ -38,7 +38,7 @@ class ScheduleMessages extends ScheduleBase
} }
$now = DateTime::now(); $now = DateTime::now();
$scheduledAt = DateTime::formatTz($schedule['scheduledAt']); $scheduledAt = DateTime::formatTz($schedule['schedule']);
if ($scheduledAt > $now) { if ($scheduledAt > $now) {
continue; continue;

View file

@ -97,7 +97,7 @@ class Messaging extends Action
if (\count($topicIds) > 0) { if (\count($topicIds) > 0) {
$topics = $dbForProject->find('topics', [ $topics = $dbForProject->find('topics', [
Query::equal('$id', $topicIds), Query::equal('$id', $topicIds),
Query::limit($topicIds) Query::limit(\count($topicIds)),
]); ]);
foreach ($topics as $topic) { foreach ($topics as $topic) {
$targets = \array_filter($topic->getAttribute('targets'), fn(Document $target) => $targets = \array_filter($topic->getAttribute('targets'), fn(Document $target) =>
@ -109,7 +109,7 @@ class Messaging extends Action
if (\count($userIds) > 0) { if (\count($userIds) > 0) {
$users = $dbForProject->find('users', [ $users = $dbForProject->find('users', [
Query::equal('$id', $userIds), Query::equal('$id', $userIds),
Query::limit($userIds) Query::limit(\count($userIds)),
]); ]);
foreach ($users as $user) { foreach ($users as $user) {
$targets = \array_filter($user->getAttribute('targets'), fn(Document $target) => $targets = \array_filter($user->getAttribute('targets'), fn(Document $target) =>
@ -121,14 +121,18 @@ class Messaging extends Action
if (\count($targetIds) > 0) { if (\count($targetIds) > 0) {
$targets = $dbForProject->find('targets', [ $targets = $dbForProject->find('targets', [
Query::equal('$id', $targetIds), Query::equal('$id', $targetIds),
Query::limit($targetIds) Query::limit(\count($targetIds)),
]); ]);
$recipients = \array_merge($recipients, $targets); $recipients = \array_merge($recipients, $targets);
} }
if (empty($recipients)) { if (empty($recipients)) {
Console::error('No valid recipients found.'); $dbForProject->updateDocument('messages', $message->getId(), $message->setAttributes([
return; 'status' => 'failed',
'deliveryErrors' => ['No valid recipients found.']
]));
throw new \Exception('No valid recipients found.');
} }
$fallback = $dbForProject->findOne('providers', [ $fallback = $dbForProject->findOne('providers', [
@ -137,8 +141,12 @@ class Messaging extends Action
]); ]);
if ($fallback === false || $fallback->isEmpty()) { if ($fallback === false || $fallback->isEmpty()) {
Console::error('No fallback provider found.'); $dbForProject->updateDocument('messages', $message->getId(), $message->setAttributes([
return; 'status' => 'failed',
'deliveryErrors' => ['No fallback provider found.']
]));
throw new \Exception('No fallback provider found.');
} }
/** /**