Skip to content

Commit 68a1227

Browse files
committed
feat(schedule): 任务调度模块未启用时,增加默认提示
1 parent 5e7a2a4 commit 68a1227

File tree

4 files changed

+80
-0
lines changed

4 files changed

+80
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package top.continew.admin.schedule.annotation;
18+
19+
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
20+
import top.continew.starter.core.constant.PropertiesConstants;
21+
22+
import java.lang.annotation.*;
23+
24+
/**
25+
* 是否禁用 Snail Job 判断注解
26+
*
27+
* @author Charles7c
28+
* @since 2025/10/25 12:28
29+
*/
30+
@Retention(RetentionPolicy.RUNTIME)
31+
@Target({ElementType.TYPE, ElementType.METHOD})
32+
@Documented
33+
@ConditionalOnProperty(prefix = "snail-job", name = PropertiesConstants.ENABLED, havingValue = "false")
34+
public @interface ConditionalOnDisabledScheduleJob {
35+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package top.continew.admin.schedule.controller;
18+
19+
import org.springframework.http.HttpStatus;
20+
import org.springframework.web.bind.annotation.RequestMapping;
21+
import org.springframework.web.bind.annotation.RestController;
22+
import top.continew.admin.schedule.annotation.ConditionalOnDisabledScheduleJob;
23+
import top.continew.starter.web.model.R;
24+
25+
/**
26+
* 任务调度默认控制器
27+
*
28+
* @author Charles7c
29+
* @since 2025/10/25 12:28
30+
*/
31+
@RestController
32+
@ConditionalOnDisabledScheduleJob
33+
@RequestMapping({"/schedule/job", "/schedule/log"})
34+
public class DefaultController {
35+
36+
@RequestMapping("/**")
37+
public R error() {
38+
return R.fail(String.valueOf(HttpStatus.INTERNAL_SERVER_ERROR
39+
.value()), "任务模块已禁用,请于对应环境配置文件中配置 snail-job.enabled 为 true 进行启用");
40+
}
41+
}

continew-plugin/continew-plugin-schedule/src/main/java/top/continew/admin/schedule/controller/JobController.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import lombok.RequiredArgsConstructor;
2626
import org.springframework.validation.annotation.Validated;
2727
import org.springframework.web.bind.annotation.*;
28+
import top.continew.admin.schedule.annotation.ConditionalOnEnabledScheduleJob;
2829
import top.continew.admin.schedule.model.query.JobQuery;
2930
import top.continew.admin.schedule.model.req.JobReq;
3031
import top.continew.admin.schedule.model.req.JobStatusReq;
@@ -48,6 +49,7 @@
4849
@Tag(name = " 任务 API")
4950
@RestController
5051
@RequiredArgsConstructor
52+
@ConditionalOnEnabledScheduleJob
5153
@RequestMapping("/schedule/job")
5254
public class JobController {
5355

continew-plugin/continew-plugin-schedule/src/main/java/top/continew/admin/schedule/controller/JobLogController.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import jakarta.validation.Valid;
2525
import lombok.RequiredArgsConstructor;
2626
import org.springframework.web.bind.annotation.*;
27+
import top.continew.admin.schedule.annotation.ConditionalOnEnabledScheduleJob;
2728
import top.continew.admin.schedule.model.query.JobLogQuery;
2829
import top.continew.admin.schedule.model.resp.JobLogResp;
2930
import top.continew.admin.schedule.service.JobLogService;
@@ -39,6 +40,7 @@
3940
@Tag(name = " 任务日志 API")
4041
@RestController
4142
@RequiredArgsConstructor
43+
@ConditionalOnEnabledScheduleJob
4244
@RequestMapping("/schedule/log")
4345
public class JobLogController {
4446

0 commit comments

Comments
 (0)