From 056eb8a3731c4a50d8954eb03487f7e8c3401179 Mon Sep 17 00:00:00 2001 From: Charles7c Date: Sun, 18 May 2025 15:33:38 +0800 Subject: [PATCH] =?UTF-8?q?feat(schedule):=20=E6=96=B0=E5=A2=9E=20Conditio?= =?UTF-8?q?nalOnEnabledScheduleJob=20=E6=B3=A8=E8=A7=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ConditionalOnEnabledScheduleJob.java | 35 +++++++++++++++++++ .../config/SnailJobConfiguration.java | 4 +-- 2 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 continew-plugin/continew-plugin-schedule/src/main/java/top/continew/admin/schedule/annotation/ConditionalOnEnabledScheduleJob.java diff --git a/continew-plugin/continew-plugin-schedule/src/main/java/top/continew/admin/schedule/annotation/ConditionalOnEnabledScheduleJob.java b/continew-plugin/continew-plugin-schedule/src/main/java/top/continew/admin/schedule/annotation/ConditionalOnEnabledScheduleJob.java new file mode 100644 index 00000000..59d0e7a2 --- /dev/null +++ b/continew-plugin/continew-plugin-schedule/src/main/java/top/continew/admin/schedule/annotation/ConditionalOnEnabledScheduleJob.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2022-present Charles7c Authors. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package top.continew.admin.schedule.annotation; + +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import top.continew.starter.core.constant.PropertiesConstants; + +import java.lang.annotation.*; + +/** + * 是否启用 Snail Job 注解 + * + * @author Charles7c + * @since 2025/5/18 12:03 + */ +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.TYPE, ElementType.METHOD}) +@Documented +@ConditionalOnProperty(prefix = "snail-job", name = PropertiesConstants.ENABLED, havingValue = "true", matchIfMissing = true) +public @interface ConditionalOnEnabledScheduleJob { +} \ No newline at end of file diff --git a/continew-plugin/continew-plugin-schedule/src/main/java/top/continew/admin/schedule/config/SnailJobConfiguration.java b/continew-plugin/continew-plugin-schedule/src/main/java/top/continew/admin/schedule/config/SnailJobConfiguration.java index c9bc2083..193fa18c 100644 --- a/continew-plugin/continew-plugin-schedule/src/main/java/top/continew/admin/schedule/config/SnailJobConfiguration.java +++ b/continew-plugin/continew-plugin-schedule/src/main/java/top/continew/admin/schedule/config/SnailJobConfiguration.java @@ -23,9 +23,9 @@ import com.aizuda.snailjob.client.common.appender.SnailLogbackAppender; import com.aizuda.snailjob.client.common.event.SnailClientStartingEvent; import com.aizuda.snailjob.client.starter.EnableSnailJob; import org.slf4j.LoggerFactory; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Configuration; import org.springframework.context.event.EventListener; +import top.continew.admin.schedule.annotation.ConditionalOnEnabledScheduleJob; /** * Snail Job 配置 @@ -35,7 +35,7 @@ import org.springframework.context.event.EventListener; */ @Configuration @EnableSnailJob -@ConditionalOnProperty(prefix = "snail-job", value = "enabled", havingValue = "true", matchIfMissing = true) +@ConditionalOnEnabledScheduleJob public class SnailJobConfiguration { /**