From be9728937a5eb6bab618fb4dd5b026fabce92fc5 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Wed, 17 Jan 2024 14:35:12 +1300 Subject: [PATCH 1/3] Update src/Appwrite/Platform/Tasks/ScheduleMessages.php Co-authored-by: Steven Nguyen <1477010+stnguyen90@users.noreply.github.com> --- src/Appwrite/Platform/Tasks/ScheduleMessages.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Appwrite/Platform/Tasks/ScheduleMessages.php b/src/Appwrite/Platform/Tasks/ScheduleMessages.php index 471aeb8f2a..19fc426637 100644 --- a/src/Appwrite/Platform/Tasks/ScheduleMessages.php +++ b/src/Appwrite/Platform/Tasks/ScheduleMessages.php @@ -34,7 +34,7 @@ class ScheduleMessages extends ScheduleBase { foreach ($this->schedules as $schedule) { $now = DateTime::now(); - $scheduledAt = DateTime::formatTz($schedule['scheduledAt']); + $scheduledAt = DateTime::formatTz($schedule['schedule']); if ($scheduledAt > $now) { continue; From 0ffe1d5346887e546bf3655fee8f454a1f439b93 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Wed, 17 Jan 2024 14:54:25 +1300 Subject: [PATCH 2/3] Fix limits --- src/Appwrite/Platform/Workers/Messaging.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Appwrite/Platform/Workers/Messaging.php b/src/Appwrite/Platform/Workers/Messaging.php index d0e47d1133..3267a9034e 100644 --- a/src/Appwrite/Platform/Workers/Messaging.php +++ b/src/Appwrite/Platform/Workers/Messaging.php @@ -97,7 +97,7 @@ class Messaging extends Action if (\count($topicIds) > 0) { $topics = $dbForProject->find('topics', [ Query::equal('$id', $topicIds), - Query::limit($topicIds) + Query::limit(\count($topicIds)), ]); foreach ($topics as $topic) { $targets = \array_filter($topic->getAttribute('targets'), fn(Document $target) => @@ -109,7 +109,7 @@ class Messaging extends Action if (\count($userIds) > 0) { $users = $dbForProject->find('users', [ Query::equal('$id', $userIds), - Query::limit($userIds) + Query::limit(\count($userIds)), ]); foreach ($users as $user) { $targets = \array_filter($user->getAttribute('targets'), fn(Document $target) => @@ -121,7 +121,7 @@ class Messaging extends Action if (\count($targetIds) > 0) { $targets = $dbForProject->find('targets', [ Query::equal('$id', $targetIds), - Query::limit($targetIds) + Query::limit(\count($targetIds)), ]); $recipients = \array_merge($recipients, $targets); } From aee1d4406289c92651e3af3396ba79b5d0c97373 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Wed, 17 Jan 2024 14:57:29 +1300 Subject: [PATCH 3/3] Set failed and delivery errors for failure cases --- src/Appwrite/Platform/Workers/Messaging.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/Appwrite/Platform/Workers/Messaging.php b/src/Appwrite/Platform/Workers/Messaging.php index 3267a9034e..cf05b42d43 100644 --- a/src/Appwrite/Platform/Workers/Messaging.php +++ b/src/Appwrite/Platform/Workers/Messaging.php @@ -127,8 +127,12 @@ class Messaging extends Action } if (empty($recipients)) { - Console::error('No valid recipients found.'); - return; + $dbForProject->updateDocument('messages', $message->getId(), $message->setAttributes([ + 'status' => 'failed', + 'deliveryErrors' => ['No valid recipients found.'] + ])); + + throw new \Exception('No valid recipients found.'); } $fallback = $dbForProject->findOne('providers', [ @@ -137,8 +141,12 @@ class Messaging extends Action ]); if ($fallback === false || $fallback->isEmpty()) { - Console::error('No fallback provider found.'); - return; + $dbForProject->updateDocument('messages', $message->getId(), $message->setAttributes([ + 'status' => 'failed', + 'deliveryErrors' => ['No fallback provider found.'] + ])); + + throw new \Exception('No fallback provider found.'); } /**