diff --git a/composer.json b/composer.json index d87c4cc..6889d7a 100644 --- a/composer.json +++ b/composer.json @@ -50,7 +50,10 @@ "name": "fas fa-tasks", "backgroundColor": "#00a7e3", "color": "#fff" - } + }, + "optional-dependencies": [ + "blomstra/horizon" + ] }, "extiverse": { "discuss": "https://discuss.flarum.org/d/27455" diff --git a/extend.php b/extend.php index 96a946d..a4344d9 100644 --- a/extend.php +++ b/extend.php @@ -22,6 +22,7 @@ return [ new Extend\Locales(__DIR__ . '/resources/locale'), + new GBExtend\ConfigureHorizon(), new GBExtend\EnableRedis(), (new Extend\ServiceProvider()) diff --git a/js/src/admin/index.js b/js/src/admin/index.js index 0f67df3..c0d324f 100644 --- a/js/src/admin/index.js +++ b/js/src/admin/index.js @@ -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; diff --git a/resources/locale/en.yml b/resources/locale/en.yml index 87fbc46..2d5fb06 100644 --- a/resources/locale/en.yml +++ b/resources/locale/en.yml @@ -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 (new \Blomstra\Horizon\Extend\Horizon)->config(...)) diff --git a/src/Extend/ConfigureHorizon.php b/src/Extend/ConfigureHorizon.php new file mode 100644 index 0000000..4a14588 --- /dev/null +++ b/src/Extend/ConfigureHorizon.php @@ -0,0 +1,45 @@ +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); + } +}