[COMPONENT][FreeNetwork] Start using queues
[COMPONENT][Notification] Start using queues [PLUGIN][ActivityPub] Start using queues
This commit is contained in:
@@ -26,6 +26,7 @@ use App\Core\Event;
|
||||
use function App\Core\I18n\_m;
|
||||
use App\Core\Log;
|
||||
use App\Core\Modules\Component;
|
||||
use App\Core\Queue\Queue;
|
||||
use App\Core\Router\RouteLoader;
|
||||
use App\Core\Router\Router;
|
||||
use App\Entity\Activity;
|
||||
@@ -74,8 +75,25 @@ class Notification extends Component
|
||||
return Event::next;
|
||||
}
|
||||
|
||||
public function onQueueNotificationLocal(Actor $sender, Activity $activity, Actor $target, ?string $reason, array &$retry_args): bool
|
||||
{
|
||||
// TODO: use https://symfony.com/doc/current/notifier.html
|
||||
return Event::stop;
|
||||
}
|
||||
|
||||
public function onQueueNotificationRemote(Actor $sender, Activity $activity, array $targets, ?string $reason, array &$retry_args): bool
|
||||
{
|
||||
if (FreeNetwork::notify($sender, $activity, $targets, $reason)) {
|
||||
return Event::stop;
|
||||
} else {
|
||||
return Event::next;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Bring given Activity to Targets's attention
|
||||
*
|
||||
* @return true if successful, false otherwise
|
||||
*/
|
||||
public static function notify(Actor $sender, Activity $activity, array $targets, ?string $reason = null): bool
|
||||
{
|
||||
@@ -92,8 +110,12 @@ class Notification extends Component
|
||||
// The target already knows about this, no need to bother with a notification
|
||||
continue;
|
||||
}
|
||||
// TODO: use https://symfony.com/doc/current/notifier.html
|
||||
}
|
||||
Queue::enqueue(
|
||||
payload: [$sender, $activity, $target, $reason],
|
||||
queue: 'notification_local',
|
||||
priority: true,
|
||||
);
|
||||
} else {
|
||||
// We have no authority nor responsibility of notifying remote actors of a remote actor's doing
|
||||
if ($sender->getIsLocal()) {
|
||||
@@ -115,8 +137,14 @@ class Notification extends Component
|
||||
}
|
||||
}
|
||||
|
||||
FreeNetwork::notify($sender, $activity, $remote_targets, $reason);
|
||||
if ($remote_targets !== []) {
|
||||
Queue::enqueue(
|
||||
payload: [$sender, $activity, $remote_targets, $reason],
|
||||
queue: 'notification_remote',
|
||||
priority: false,
|
||||
);
|
||||
}
|
||||
|
||||
return Event::next;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user