Add startup handling for enterprise environment

This commit is contained in:
Thorsten Sommer 2025-06-02 15:59:24 +02:00
parent d10f2af9f7
commit 1a1a385a0b
No known key found for this signature in database
GPG Key ID: B0B7E2FC074BF1F5
3 changed files with 17 additions and 4 deletions

View File

@ -9,6 +9,7 @@ using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Routing; using Microsoft.AspNetCore.Components.Routing;
using DialogOptions = AIStudio.Dialogs.DialogOptions; using DialogOptions = AIStudio.Dialogs.DialogOptions;
using EnterpriseEnvironment = AIStudio.Tools.EnterpriseEnvironment;
namespace AIStudio.Layout; namespace AIStudio.Layout;
@ -204,7 +205,14 @@ public partial class MainLayout : LayoutComponentBase, IMessageBusReceiver, ILan
// Ensure that all internal plugins are present: // Ensure that all internal plugins are present:
await PluginFactory.EnsureInternalPlugins(); await PluginFactory.EnsureInternalPlugins();
// Load (but not start) all plugins, without waiting for them: //
// Check if there is an enterprise configuration plugin to download:
//
var enterpriseEnvironment = this.MessageBus.CheckDeferredMessages<EnterpriseEnvironment>(Event.STARTUP_ENTERPRISE_ENVIRONMENT).FirstOrDefault();
if(enterpriseEnvironment != default)
await PluginFactory.TryDownloadingConfigPluginAsync(enterpriseEnvironment.ConfigurationId, enterpriseEnvironment.ConfigurationServerUrl);
// Load (but not start) all plugins without waiting for them:
var pluginLoadingTimeout = new CancellationTokenSource(TimeSpan.FromSeconds(5)); var pluginLoadingTimeout = new CancellationTokenSource(TimeSpan.FromSeconds(5));
await PluginFactory.LoadAll(pluginLoadingTimeout.Token); await PluginFactory.LoadAll(pluginLoadingTimeout.Token);

View File

@ -9,6 +9,7 @@ public enum Event
CONFIGURATION_CHANGED, CONFIGURATION_CHANGED,
COLOR_THEME_CHANGED, COLOR_THEME_CHANGED,
STARTUP_PLUGIN_SYSTEM, STARTUP_PLUGIN_SYSTEM,
STARTUP_ENTERPRISE_ENVIRONMENT,
PLUGINS_RELOADED, PLUGINS_RELOADED,
SHOW_ERROR, SHOW_ERROR,
SHOW_WARNING, SHOW_WARNING,

View File

@ -14,7 +14,7 @@ public sealed class EnterpriseEnvironmentService(ILogger<EnterpriseEnvironmentSe
{ {
logger.LogInformation("The enterprise environment service was initialized."); logger.LogInformation("The enterprise environment service was initialized.");
await this.StartUpdating(); await this.StartUpdating(isFirstRun: true);
while (!stoppingToken.IsCancellationRequested) while (!stoppingToken.IsCancellationRequested)
{ {
await Task.Delay(CHECK_INTERVAL, stoppingToken); await Task.Delay(CHECK_INTERVAL, stoppingToken);
@ -24,7 +24,7 @@ public sealed class EnterpriseEnvironmentService(ILogger<EnterpriseEnvironmentSe
#endregion #endregion
private async Task StartUpdating() private async Task StartUpdating(bool isFirstRun = false)
{ {
try try
{ {
@ -63,6 +63,10 @@ public sealed class EnterpriseEnvironmentService(ILogger<EnterpriseEnvironmentSe
default: default:
logger.LogInformation($"AI Studio runs with an enterprise configuration id ('{enterpriseConfigId}') and configuration server URL ('{enterpriseConfigServerUrl}')."); logger.LogInformation($"AI Studio runs with an enterprise configuration id ('{enterpriseConfigId}') and configuration server URL ('{enterpriseConfigServerUrl}').");
if(isFirstRun)
MessageBus.INSTANCE.DeferMessage(null, Event.STARTUP_ENTERPRISE_ENVIRONMENT, new EnterpriseEnvironment(enterpriseConfigServerUrl, enterpriseConfigId, etag));
else
await PluginFactory.TryDownloadingConfigPluginAsync(enterpriseConfigId, enterpriseConfigServerUrl); await PluginFactory.TryDownloadingConfigPluginAsync(enterpriseConfigId, enterpriseConfigServerUrl);
break; break;
} }