gnu-social/docs/developer/src/queue.md

48 lines
1.4 KiB
Markdown
Raw Permalink Normal View History

2021-08-03 15:35:23 +01:00
# Queue
2021-08-03 15:35:23 +01:00
Some activities that GNU social can do, like broadcasting with OStatus or
ActivityPub, XMPP messages and SMS operations, can be 'queued' and done by
asynchronous daemons instead.
## Running Queues
Run the queue handler with:
```sh
php bin/console messenger:consume async --limit=10 --memory-limit=128M --time-limit=3600
```
GNU social uses Symfony, therefore the [documentation on
queues](https://symfony.com/doc/current/messenger.html#deploying-to-production)
might be useful.
2021-08-03 15:35:23 +01:00
## Definitions
2021-08-03 15:35:23 +01:00
* Message - A Message holds the data to be handled (a variable) and the queue name (a string).
* QueueHandler - A QueueHandler is an event listener that expects to receive data from the queue.
* Enqueuer - An Enqueuer is any arbitrary code that wishes to send data to a queue.
* Transporter - The Transporter is given a Message by an Enqueuer. The Transporter is responsible
for ensuring that the Message is passed to all relevant QueueHandlers.
2021-08-03 15:35:23 +01:00
## Using Queues
2021-08-03 15:35:23 +01:00
Queues are akin to events.
2021-08-03 15:35:23 +01:00
In your plugin you can call `App\Core\Queue::enqueue` and send a message to
be handled by the queue:
2021-08-03 15:35:23 +01:00
```php
Queue::enqueue($hello_world, 'MyFirstQueue');
```
2021-08-03 15:35:23 +01:00
and then receive with:
2021-08-03 15:35:23 +01:00
```php
public function onMyFirstQueue($data): bool
{
// Do something with $data
return Event::next;
}
```
2021-08-03 15:35:23 +01:00
GNU social comes with a set of core queues with often wanted data: TODO Elaborate.