Merge remote-tracking branch 'origin/feat-message-scheduling' into feat-maintenance-delete-expired-targets
This commit is contained in:
commit
ad40e0a3c5
2 changed files with 16 additions and 8 deletions
|
@ -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;
|
||||||
|
|
|
@ -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.');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue