Procházet zdrojové kódy

定时任务出错时保存异常信息到日志文件

sunyj před 9 roky
rodič
revize
a76cd8238c

+ 3 - 3
search-console-b2b/src/main/java/com/uas/search/console/b2b/schedule/service/impl/TaskServiceImpl.java

@@ -153,10 +153,10 @@ public class TaskServiceImpl implements TaskService {
 					logger.info("Task run...");
 					Executable command = taskInformation.getCommand();
 					String result = command.execute();
-					TaskLog taskLog = new TaskLog(taskInformation, new Date(), result);
-					saveLog(taskLog);
+					saveLog(new TaskLog(taskInformation, new Date(), result));
 				} catch (Exception e) {
-					e.printStackTrace();
+					saveLog(new TaskLog(taskInformation, new Date(),
+							"定时任务出错" + new SearchException(e).getDetailedMessage(e)));
 				}
 			}
 		};

+ 3 - 3
search-console/src/main/java/com/uas/search/console/schedule/service/impl/TaskServiceImpl.java

@@ -152,10 +152,10 @@ public class TaskServiceImpl implements TaskService {
 					logger.info("Task run...");
 					Executable command = taskInformation.getCommand();
 					String result = command.execute();
-					TaskLog taskLog = new TaskLog(taskInformation, new Date(), result);
-					saveLog(taskLog);
+					saveLog(new TaskLog(taskInformation, new Date(), result));
 				} catch (Exception e) {
-					e.printStackTrace();
+					saveLog(new TaskLog(taskInformation, new Date(),
+							"定时任务出错" + new SearchException(e).getDetailedMessage(e)));
 				}
 			}
 		};