瀏覽代碼

[scheduler] 解决采集任务内容更新时调度失效问题,数据库连接失效导致应用异常

tomsun28 4 年之前
父節點
當前提交
6e3ad838e3
共有 3 個文件被更改,包括 20 次插入2 次删除
  1. 1 1
      .gitignore
  2. 1 1
      RequestDemo.json
  3. 18 0
      manager/src/main/java/com/usthe/manager/support/GlobalExceptionHandler.java

+ 1 - 1
.gitignore

@@ -9,7 +9,7 @@ micronaut-cli.yml
 .mvn/
 mvnw
 mvnw.bat
-.log
+*.log
 
 ### STS ###
 .apt_generated

+ 1 - 1
RequestDemo.json

@@ -22,7 +22,7 @@
       "id": 87584674384,
       "monitorId": 875846754543,
       "type": 1,
-      "value": "80"
+      "value": "8088"
     },
     {
       "field": "host",

+ 18 - 0
manager/src/main/java/com/usthe/manager/support/GlobalExceptionHandler.java

@@ -4,6 +4,7 @@ package com.usthe.manager.support;
 import com.usthe.common.entity.dto.Message;
 import com.usthe.manager.support.exception.MonitorDatabaseException;
 import com.usthe.manager.support.exception.MonitorDetectException;
+import com.usthe.scheduler.ScheduleException;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.dao.DataAccessException;
 import org.springframework.http.HttpStatus;
@@ -135,6 +136,23 @@ public class GlobalExceptionHandler {
     }
 
     /**
+     * 处理分发调度器异常问题
+     * @param exception 调度器异常问题
+     * @return response
+     */
+    @ExceptionHandler(ScheduleException.class)
+    @ResponseBody
+    ResponseEntity<Message<Void>> handleScheduleException(ScheduleException exception) {
+        String errorMessage = "scheduler warning";
+        if (exception != null) {
+            errorMessage = exception.getMessage();
+        }
+        log.warn("[scheduler warning]-{}", errorMessage);
+        Message<Void> message = Message.<Void>builder().msg(errorMessage).build();
+        return ResponseEntity.status(HttpStatus.CONFLICT).body(message);
+    }
+
+    /**
      * handler the exception thrown for datastore error
      * @param exception datastore exception
      * @return response