forked from clone/flarum-ext-redis-setup
Added the ability to configure horizon
This commit is contained in:
@@ -50,7 +50,10 @@
|
||||
"name": "fas fa-tasks",
|
||||
"backgroundColor": "#00a7e3",
|
||||
"color": "#fff"
|
||||
}
|
||||
},
|
||||
"optional-dependencies": [
|
||||
"blomstra/horizon"
|
||||
]
|
||||
},
|
||||
"extiverse": {
|
||||
"discuss": "https://discuss.flarum.org/d/27455"
|
||||
|
||||
@@ -22,6 +22,7 @@ return [
|
||||
|
||||
new Extend\Locales(__DIR__ . '/resources/locale'),
|
||||
|
||||
new GBExtend\ConfigureHorizon(),
|
||||
new GBExtend\EnableRedis(),
|
||||
|
||||
(new Extend\ServiceProvider())
|
||||
|
||||
@@ -36,6 +36,15 @@ app.initializers.add(slug, () => {
|
||||
label: t(`${prfx}.enable_queue`),
|
||||
});
|
||||
|
||||
if (app.initializers.has('blomstra/horizon')) {
|
||||
app.extensionData.for(slug).registerSetting({
|
||||
setting: 'glowingblue-redis.horizonConfig',
|
||||
type: 'textarea',
|
||||
label: t(`${prfx}.horizon_config`),
|
||||
help: t(`${prfx}.horizon_help_text`),
|
||||
});
|
||||
}
|
||||
|
||||
extend(StatusWidget.prototype, 'items', (items) => {
|
||||
const loads = app.data.blomstraQueuesLoad;
|
||||
|
||||
|
||||
@@ -5,3 +5,5 @@ glowingblue-redis-setup:
|
||||
enable_redis_sessions:
|
||||
Enable Redis sessions (all users will be logged out after changing this setting)
|
||||
enable_queue: Enable Redis queue
|
||||
horizon_config: "Horizon config (format: JSON)."
|
||||
horizon_help_text: This will be passed to <code>(new \Blomstra\Horizon\Extend\Horizon)->config(...))</code>
|
||||
|
||||
45
src/Extend/ConfigureHorizon.php
Normal file
45
src/Extend/ConfigureHorizon.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of glowingblue/redis-setup.
|
||||
*
|
||||
* Copyright (c) 2022 Glowing Blue AG.
|
||||
* Authors: Rafael Horvat.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE.md
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace GlowingBlue\RedisSetup\Extend;
|
||||
|
||||
use Blomstra\Horizon\Extend\Horizon;
|
||||
use Flarum\Extend\ExtenderInterface;
|
||||
use Flarum\Extension\Extension;
|
||||
use Flarum\Extension\ExtensionManager;
|
||||
use Flarum\Settings\SettingsRepositoryInterface;
|
||||
use Illuminate\Contracts\Container\Container;
|
||||
|
||||
class ConfigureHorizon implements ExtenderInterface
|
||||
{
|
||||
public function extend(Container $container, Extension $extension = null)
|
||||
{
|
||||
$extensions = resolve(ExtensionManager::class);
|
||||
|
||||
if (!$extensions->isEnabled('blomstra-horizon') || !class_exists(Horizon::class)) {
|
||||
return;
|
||||
}
|
||||
|
||||
/** @var SettingsRepositoryInterface */
|
||||
$settings = resolve(SettingsRepositoryInterface::class);
|
||||
|
||||
$config = json_decode($settings->get('glowingblue-redis.horizonConfig', '[]'), true);
|
||||
|
||||
if (!is_array($config) || empty($config)) {
|
||||
return;
|
||||
}
|
||||
|
||||
(new Horizon())
|
||||
->config($config)
|
||||
->extend($container, $extension);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user