Compare commits
No commits in common. "master" and "v1.0.5" have entirely different histories.
@ -3,7 +3,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>hxuanyu-spring-boot-starter-parent</artifactId>
|
<artifactId>hxuanyu-spring-boot-starter-parent</artifactId>
|
||||||
<groupId>com.hxuanyu</groupId>
|
<groupId>com.hxuanyu</groupId>
|
||||||
<version>1.0.7-SNAPSHOT</version>
|
<version>1.0.5</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>hxuanyu-spring-boot-starter-parent</artifactId>
|
<artifactId>hxuanyu-spring-boot-starter-parent</artifactId>
|
||||||
<groupId>com.hxuanyu</groupId>
|
<groupId>com.hxuanyu</groupId>
|
||||||
<version>1.0.7-SNAPSHOT</version>
|
<version>1.0.5</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
@ -10,11 +10,10 @@ import com.hxuanyu.monitor.common.CheckResult;
|
|||||||
* @version 1.0
|
* @version 1.0
|
||||||
*/
|
*/
|
||||||
public abstract class BaseMonitorItem {
|
public abstract class BaseMonitorItem {
|
||||||
protected String monitorItemName;
|
private String monitorItemName;
|
||||||
protected String cron;
|
private String cron;
|
||||||
|
|
||||||
public BaseMonitorItem() {
|
public BaseMonitorItem() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public BaseMonitorItem(String monitorItemName, String cron) {
|
public BaseMonitorItem(String monitorItemName, String cron) {
|
||||||
@ -22,11 +21,6 @@ public abstract class BaseMonitorItem {
|
|||||||
this.cron = cron;
|
this.cron = cron;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BaseMonitorItem(String cron) {
|
|
||||||
this.monitorItemName = getClass().getSimpleName();
|
|
||||||
this.cron = cron;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getMonitorItemName() {
|
public String getMonitorItemName() {
|
||||||
return monitorItemName;
|
return monitorItemName;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package com.hxuanyu.monitor.manager;
|
package com.hxuanyu.monitor.manager;
|
||||||
|
|
||||||
import com.hxuanyu.common.message.Msg;
|
import com.hxuanyu.common.message.Msg;
|
||||||
import com.hxuanyu.common.spring.SpringContextUtil;
|
|
||||||
import com.hxuanyu.monitor.annotation.MonitorItem;
|
import com.hxuanyu.monitor.annotation.MonitorItem;
|
||||||
import com.hxuanyu.monitor.base.BaseMonitorItem;
|
import com.hxuanyu.monitor.base.BaseMonitorItem;
|
||||||
import com.hxuanyu.monitor.common.CheckResult;
|
import com.hxuanyu.monitor.common.CheckResult;
|
||||||
@ -69,7 +68,7 @@ public class MonitorItemBeanManager implements ApplicationListener<ContextRefres
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Msg<String> addMonitorTask(BaseMonitorItem item) {
|
public Msg<String> addMonitorTask(BaseMonitorItem item) {
|
||||||
String taskId = item.getMonitorItemName();
|
String taskId = "ScheduledTask-" + item.getMonitorItemName();
|
||||||
if (MONITOR_ITEM_MAP.containsKey(taskId)) {
|
if (MONITOR_ITEM_MAP.containsKey(taskId)) {
|
||||||
return Msg.failed("任务已经存在,请执行修改操作");
|
return Msg.failed("任务已经存在,请执行修改操作");
|
||||||
}
|
}
|
||||||
@ -79,22 +78,13 @@ public class MonitorItemBeanManager implements ApplicationListener<ContextRefres
|
|||||||
return Msg.success("添加成功");
|
return Msg.success("添加成功");
|
||||||
}
|
}
|
||||||
|
|
||||||
public Msg<String> addMonitorTask(String itemName, Class<? extends BaseMonitorItem> clazz, Object... args) {
|
|
||||||
BaseMonitorItem item = SpringContextUtil.registerBean(itemName, clazz, args);
|
|
||||||
return addMonitorTask(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Msg<String> addMonitorTask(Class<? extends BaseMonitorItem> clazz, Object... args) {
|
|
||||||
return addMonitorTask(clazz.getSimpleName(), clazz, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Msg<String> setMonitorTaskCron(String taskId, String cron) {
|
public Msg<String> setMonitorTaskCron(String taskId, String cron) {
|
||||||
if (MONITOR_ITEM_MAP.containsKey(taskId)) {
|
if (MONITOR_ITEM_MAP.containsKey(taskId)) {
|
||||||
schedulingConfigurer.cancelTriggerTask(taskId);
|
schedulingConfigurer.cancelTriggerTask(taskId);
|
||||||
BaseMonitorItem item = MONITOR_ITEM_MAP.get(taskId);
|
BaseMonitorItem item = MONITOR_ITEM_MAP.get(taskId);
|
||||||
item.setCron(cron);
|
item.setCron(cron);
|
||||||
addTask(taskId, item);
|
addTask(taskId, item);
|
||||||
logger.info("修改定时任务:{}, 执行周期:{}", taskId,item.getCron());
|
logger.info("修改定时任务:{}, 执行周期:{}", taskId, item.getCron());
|
||||||
return Msg.success("修改成功");
|
return Msg.success("修改成功");
|
||||||
} else {
|
} else {
|
||||||
return Msg.failed("修改失败,该任务不存在");
|
return Msg.failed("修改失败,该任务不存在");
|
||||||
@ -117,7 +107,7 @@ public class MonitorItemBeanManager implements ApplicationListener<ContextRefres
|
|||||||
schedulingConfigurer.resetTriggerTask(taskId, new TriggerTask(() -> {
|
schedulingConfigurer.resetTriggerTask(taskId, new TriggerTask(() -> {
|
||||||
CheckResult checkResult = item.check();
|
CheckResult checkResult = item.check();
|
||||||
if (checkResult.isTriggered()) {
|
if (checkResult.isTriggered()) {
|
||||||
if (NotifyType.TYPE_CUSTOM.equals(checkResult.getNotifyType())) {
|
if (NotifyType.TYPE_CUSTOM.equals(checkResult.getNotifyType())){
|
||||||
logger.info("定时任务[{}]触发成功,执行自定义通知", taskId);
|
logger.info("定时任务[{}]触发成功,执行自定义通知", taskId);
|
||||||
notifyService.notify(checkResult.getCustomNotify());
|
notifyService.notify(checkResult.getCustomNotify());
|
||||||
} else {
|
} else {
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>hxuanyu-spring-boot-starter-parent</artifactId>
|
<artifactId>hxuanyu-spring-boot-starter-parent</artifactId>
|
||||||
<groupId>com.hxuanyu</groupId>
|
<groupId>com.hxuanyu</groupId>
|
||||||
<version>1.0.7-SNAPSHOT</version>
|
<version>1.0.5</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>hxuanyu-spring-boot-starter-parent</artifactId>
|
<artifactId>hxuanyu-spring-boot-starter-parent</artifactId>
|
||||||
<groupId>com.hxuanyu</groupId>
|
<groupId>com.hxuanyu</groupId>
|
||||||
<version>1.0.7-SNAPSHOT</version>
|
<version>1.0.5</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
4
pom.xml
4
pom.xml
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
<groupId>com.hxuanyu</groupId>
|
<groupId>com.hxuanyu</groupId>
|
||||||
<artifactId>hxuanyu-spring-boot-starter-parent</artifactId>
|
<artifactId>hxuanyu-spring-boot-starter-parent</artifactId>
|
||||||
<version>1.0.7-SNAPSHOT</version>
|
<version>1.0.5</version>
|
||||||
<name>hxuanyu-spring-boot-starter-parent</name>
|
<name>hxuanyu-spring-boot-starter-parent</name>
|
||||||
<description>MonitorPushingParent</description>
|
<description>MonitorPushingParent</description>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
@ -19,7 +19,7 @@
|
|||||||
<connection>scm:git:https://git.hxuanyu.com/hxuanyu/hxuanyu-spring-boot-starter.git</connection>
|
<connection>scm:git:https://git.hxuanyu.com/hxuanyu/hxuanyu-spring-boot-starter.git</connection>
|
||||||
<developerConnection>scm:git:https://git.hxuanyu.com/hxuanyu/hxuanyu-spring-boot-starter.git</developerConnection>
|
<developerConnection>scm:git:https://git.hxuanyu.com/hxuanyu/hxuanyu-spring-boot-starter.git</developerConnection>
|
||||||
<url>https://git.hxuanyu.com/hxuanyu/hxuanyu-spring-boot-starter</url>
|
<url>https://git.hxuanyu.com/hxuanyu/hxuanyu-spring-boot-starter</url>
|
||||||
<tag>v1.0.0</tag>
|
<tag>v1.0.5</tag>
|
||||||
</scm>
|
</scm>
|
||||||
<developers>
|
<developers>
|
||||||
<developer>
|
<developer>
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>hxuanyu-spring-boot-starter-parent</artifactId>
|
<artifactId>hxuanyu-spring-boot-starter-parent</artifactId>
|
||||||
<groupId>com.hxuanyu</groupId>
|
<groupId>com.hxuanyu</groupId>
|
||||||
<version>1.0.7-SNAPSHOT</version>
|
<version>1.0.5</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
@ -2,10 +2,9 @@ package com.hxuanyu.test.controller;
|
|||||||
|
|
||||||
import com.hxuanyu.common.message.Msg;
|
import com.hxuanyu.common.message.Msg;
|
||||||
import com.hxuanyu.monitor.base.BaseMonitorItem;
|
import com.hxuanyu.monitor.base.BaseMonitorItem;
|
||||||
|
import com.hxuanyu.monitor.common.CheckResult;
|
||||||
import com.hxuanyu.monitor.manager.MonitorItemBeanManager;
|
import com.hxuanyu.monitor.manager.MonitorItemBeanManager;
|
||||||
import com.hxuanyu.test.monitor.TestMonitorItem;
|
import com.hxuanyu.notify.enums.NotifyType;
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
@ -22,7 +21,6 @@ import java.util.Map;
|
|||||||
@RequestMapping("/monitor")
|
@RequestMapping("/monitor")
|
||||||
@RestController
|
@RestController
|
||||||
public class MonitorTestController {
|
public class MonitorTestController {
|
||||||
private final Logger logger = LoggerFactory.getLogger(MonitorTestController.class);
|
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
MonitorItemBeanManager monitorItemBeanManager;
|
MonitorItemBeanManager monitorItemBeanManager;
|
||||||
@ -51,7 +49,12 @@ public class MonitorTestController {
|
|||||||
|
|
||||||
@PostMapping("/")
|
@PostMapping("/")
|
||||||
public Msg<String> addTaskList() {
|
public Msg<String> addTaskList() {
|
||||||
return monitorItemBeanManager.addMonitorTask(TestMonitorItem.class, "0/5 * * * * *");
|
return monitorItemBeanManager.addMonitorTask(new BaseMonitorItem("CustomBean", "0/10 * * * * *") {
|
||||||
|
@Override
|
||||||
|
public CheckResult check() {
|
||||||
|
return CheckResult.triggered("动态新增通知", NotifyType.TYPE_LOG);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -14,21 +14,14 @@ import org.slf4j.LoggerFactory;
|
|||||||
*
|
*
|
||||||
* @author hxuanyu
|
* @author hxuanyu
|
||||||
*/
|
*/
|
||||||
|
@MonitorItem(cron = "0/20 * * * * *")
|
||||||
public class TestMonitorItem extends BaseMonitorItem {
|
public class TestMonitorItem extends BaseMonitorItem {
|
||||||
|
|
||||||
private final Logger logger = LoggerFactory.getLogger(TestMonitorItem.class);
|
private final Logger logger = LoggerFactory.getLogger(TestMonitorItem.class);
|
||||||
|
|
||||||
public TestMonitorItem(String monitorItemName, String cron) {
|
|
||||||
super(monitorItemName, cron);
|
|
||||||
}
|
|
||||||
|
|
||||||
public TestMonitorItem(String cron) {
|
|
||||||
super(cron);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CheckResult check() {
|
public CheckResult check() {
|
||||||
|
|
||||||
double random = Math.random();
|
double random = Math.random();
|
||||||
int result = (int) (random * NotifyType.values().length);
|
int result = (int) (random * NotifyType.values().length);
|
||||||
logger.info("随机索引值:{}", result);
|
logger.info("随机索引值:{}", result);
|
||||||
|
@ -19,9 +19,7 @@ public class MonitorTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testMonitorItemScan() {
|
public void testMonitorItemScan() {
|
||||||
BaseMonitorItem testMonitorItem = monitorItemBeanManager.getMonitorItemMap().get("ScheduledTask-TestMonitorItem");
|
BaseMonitorItem testMonitorItem = monitorItemBeanManager.getMonitorItemMap().get("ScheduledTask-TestMonitorItem");
|
||||||
if (testMonitorItem != null){
|
assert testMonitorItem.getMonitorItemName() != null;
|
||||||
assert testMonitorItem.getMonitorItemName() != null;
|
logger.info("获取到的Bean:{}", testMonitorItem.toString());
|
||||||
logger.info("获取到的Bean:{}", testMonitorItem.toString());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user