2020-07-09 16:00:58 +01:00
|
|
|
<?php
|
|
|
|
|
2021-10-10 09:26:18 +01:00
|
|
|
declare(strict_types = 1);
|
|
|
|
|
2020-07-09 16:00:58 +01:00
|
|
|
// {{{ License
|
|
|
|
// This file is part of GNU social - https://www.gnu.org/software/social
|
|
|
|
//
|
|
|
|
// GNU social is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// GNU social is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
// }}}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Queue wrapper
|
|
|
|
*
|
|
|
|
* @package GNUsocial
|
|
|
|
* @category Wrapper
|
|
|
|
*
|
2021-02-19 23:29:43 +00:00
|
|
|
* @author Hugo Sales <hugo@hsal.es>
|
2022-03-27 16:21:19 +01:00
|
|
|
* @copyright 2020-2022 Free Software Foundation, Inc http://www.fsf.org
|
2020-07-09 16:00:58 +01:00
|
|
|
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
|
|
|
|
*/
|
|
|
|
|
2022-03-27 16:21:19 +01:00
|
|
|
namespace App\Core;
|
2020-07-09 16:00:58 +01:00
|
|
|
|
2022-03-27 16:21:19 +01:00
|
|
|
use App\Core\Queue\MessageHigh;
|
|
|
|
use App\Core\Queue\MessageLow;
|
2020-07-09 16:00:58 +01:00
|
|
|
use Symfony\Component\Messenger\MessageBusInterface;
|
|
|
|
|
|
|
|
abstract class Queue
|
|
|
|
{
|
|
|
|
private static ?MessageBusInterface $message_bus;
|
|
|
|
|
|
|
|
public static function setMessageBus($mb): void
|
|
|
|
{
|
|
|
|
self::$message_bus = $mb;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-08-03 15:35:23 +01:00
|
|
|
* Enqueue a $message in a configured transport, to be handled by the $queue handler
|
2020-07-09 16:00:58 +01:00
|
|
|
*
|
2021-08-08 01:37:02 +01:00
|
|
|
* @codeCoverageIgnore
|
2020-07-09 16:00:58 +01:00
|
|
|
*/
|
2022-03-05 14:22:44 +00:00
|
|
|
public static function enqueue($payload, string $queue, bool $priority = false, array $stamps = [])
|
2020-07-09 16:00:58 +01:00
|
|
|
{
|
2022-03-05 14:22:44 +00:00
|
|
|
if ($priority) {
|
|
|
|
self::$message_bus->dispatch(new MessageHigh($payload, $queue), $stamps);
|
2020-07-09 16:00:58 +01:00
|
|
|
} else {
|
2022-03-05 14:22:44 +00:00
|
|
|
self::$message_bus->dispatch(new MessageLow($payload, $queue), $stamps);
|
2020-07-09 16:00:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|