From f3023e6ec903a8c54df857fd9285cefb30c359e3 Mon Sep 17 00:00:00 2001 From: John Niang Date: Wed, 4 Jun 2025 23:47:41 +0800 Subject: [PATCH] Add a system config changed event --- .../app/infra/SystemConfigChangedEvent.java | 17 +++++++++++++++++ .../SystemConfigurableEnvironmentFetcher.java | 7 ++++++- ...ystemConfigurableEnvironmentFetcherTest.java | 15 +++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 application/src/main/java/run/halo/app/infra/SystemConfigChangedEvent.java diff --git a/application/src/main/java/run/halo/app/infra/SystemConfigChangedEvent.java b/application/src/main/java/run/halo/app/infra/SystemConfigChangedEvent.java new file mode 100644 index 000000000..259d28132 --- /dev/null +++ b/application/src/main/java/run/halo/app/infra/SystemConfigChangedEvent.java @@ -0,0 +1,17 @@ +package run.halo.app.infra; + +import org.springframework.context.ApplicationEvent; + +/** + * Event that is published when the system configuration changes. + * + * @author johnniang + * @since 2.21.0 + */ +public class SystemConfigChangedEvent extends ApplicationEvent { + + public SystemConfigChangedEvent(Object source) { + super(source); + } + +} diff --git a/application/src/main/java/run/halo/app/infra/SystemConfigurableEnvironmentFetcher.java b/application/src/main/java/run/halo/app/infra/SystemConfigurableEnvironmentFetcher.java index 2f75074c1..9a5ff70f2 100644 --- a/application/src/main/java/run/halo/app/infra/SystemConfigurableEnvironmentFetcher.java +++ b/application/src/main/java/run/halo/app/infra/SystemConfigurableEnvironmentFetcher.java @@ -12,6 +12,7 @@ import java.util.Objects; import java.util.Optional; import java.util.concurrent.atomic.AtomicReference; import org.apache.commons.lang3.StringUtils; +import org.springframework.context.ApplicationEventPublisher; import org.springframework.core.convert.ConversionService; import org.springframework.lang.NonNull; import org.springframework.stereotype.Component; @@ -39,12 +40,15 @@ import run.halo.app.infra.utils.JsonUtils; public class SystemConfigurableEnvironmentFetcher implements Reconciler { private final ReactiveExtensionClient extensionClient; private final ConversionService conversionService; + private final ApplicationEventPublisher eventPublisher; private final AtomicReference configMapCache = new AtomicReference<>(); public SystemConfigurableEnvironmentFetcher(ReactiveExtensionClient extensionClient, - ConversionService conversionService) { + ConversionService conversionService, + ApplicationEventPublisher eventPublisher) { this.extensionClient = extensionClient; this.conversionService = conversionService; + this.eventPublisher = eventPublisher; } public Mono fetch(String key, Class type) { @@ -172,6 +176,7 @@ public class SystemConfigurableEnvironmentFetcher implements Reconciler