Эх сурвалжийг харах

feat: 定时任务添加超时限制

weijianghai 1 жил өмнө
parent
commit
e391afed60

+ 12 - 1
src/main/java/com/nokia/finance/tasks/jobs/car/chengben/CarBaoXianJob.java

@@ -31,6 +31,8 @@ import java.util.ArrayList;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.TimeUnit;
 import java.util.stream.Stream;
 
 /**
@@ -67,8 +69,17 @@ public class CarBaoXianJob {
                 throw new MyRuntimeException("河北成本管理系统车辆保险数据没有文件");
             }
             for (Path path : pathList) {
-                singleJob(path);
+                CompletableFuture.runAsync(() -> {
+                    try {
+                        singleJob(path);
+                    } catch (Exception e) {
+                        throw new MyRuntimeException(e);
+                    }
+                }).get(1, TimeUnit.MINUTES);
             }
+        } catch (InterruptedException e) {
+            log.error("线程中断: {}", e.getMessage(), e);
+            Thread.currentThread().interrupt();
         } catch (Exception e) {
             log.error(e.getMessage(), e);
         }

+ 12 - 1
src/main/java/com/nokia/finance/tasks/jobs/car/chengben/CarDaWeiXiuJob.java

@@ -31,6 +31,8 @@ import java.util.ArrayList;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.TimeUnit;
 import java.util.stream.Stream;
 
 /**
@@ -67,8 +69,17 @@ public class CarDaWeiXiuJob {
                 throw new MyRuntimeException("河北成本管理系统车辆大额维修数据没有文件");
             }
             for (Path path : pathList) {
-                singleJob(path);
+                CompletableFuture.runAsync(() -> {
+                    try {
+                        singleJob(path);
+                    } catch (Exception e) {
+                        throw new MyRuntimeException(e);
+                    }
+                }).get(1, TimeUnit.MINUTES);
             }
+        } catch (InterruptedException e) {
+            log.error("线程中断: {}", e.getMessage(), e);
+            Thread.currentThread().interrupt();
         } catch (Exception e) {
             log.error(e.getMessage(), e);
         }

+ 12 - 1
src/main/java/com/nokia/finance/tasks/jobs/car/chengben/CarLuQiaoJob.java

@@ -31,6 +31,8 @@ import java.util.ArrayList;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.TimeUnit;
 import java.util.stream.Stream;
 
 /**
@@ -67,8 +69,17 @@ public class CarLuQiaoJob {
                 throw new MyRuntimeException("河北成本管理系统车辆路桥数据没有文件");
             }
             for (Path path : pathList) {
-                singleJob(path);
+                CompletableFuture.runAsync(() -> {
+                    try {
+                        singleJob(path);
+                    } catch (Exception e) {
+                        throw new MyRuntimeException(e);
+                    }
+                }).get(1, TimeUnit.MINUTES);
             }
+        } catch (InterruptedException e) {
+            log.error("线程中断: {}", e.getMessage(), e);
+            Thread.currentThread().interrupt();
         } catch (Exception e) {
             log.error(e.getMessage(), e);
         }

+ 12 - 1
src/main/java/com/nokia/finance/tasks/jobs/car/chengben/CarNianJianFeiJob.java

@@ -31,6 +31,8 @@ import java.util.ArrayList;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.TimeUnit;
 import java.util.stream.Stream;
 
 /**
@@ -67,8 +69,17 @@ public class CarNianJianFeiJob {
                 throw new MyRuntimeException("河北成本管理系统车辆年检数据没有文件");
             }
             for (Path path : pathList) {
-                singleJob(path);
+                CompletableFuture.runAsync(() -> {
+                    try {
+                        singleJob(path);
+                    } catch (Exception e) {
+                        throw new MyRuntimeException(e);
+                    }
+                }).get(1, TimeUnit.MINUTES);
             }
+        } catch (InterruptedException e) {
+            log.error("线程中断: {}", e.getMessage(), e);
+            Thread.currentThread().interrupt();
         } catch (Exception e) {
             log.error(e.getMessage(), e);
         }

+ 12 - 1
src/main/java/com/nokia/finance/tasks/jobs/car/chengben/CarQiTaJob.java

@@ -31,6 +31,8 @@ import java.util.ArrayList;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.TimeUnit;
 import java.util.stream.Stream;
 
 /**
@@ -67,8 +69,17 @@ public class CarQiTaJob {
                 throw new MyRuntimeException("河北成本管理系统车辆其他费用数据没有文件");
             }
             for (Path path : pathList) {
-                singleJob(path);
+                CompletableFuture.runAsync(() -> {
+                    try {
+                        singleJob(path);
+                    } catch (Exception e) {
+                        throw new MyRuntimeException(e);
+                    }
+                }).get(1, TimeUnit.MINUTES);
             }
+        } catch (InterruptedException e) {
+            log.error("线程中断: {}", e.getMessage(), e);
+            Thread.currentThread().interrupt();
         } catch (Exception e) {
             log.error(e.getMessage(), e);
         }

+ 12 - 1
src/main/java/com/nokia/finance/tasks/jobs/car/chengben/CarRanYouJob.java

@@ -31,6 +31,8 @@ import java.util.ArrayList;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.TimeUnit;
 import java.util.stream.Stream;
 
 /**
@@ -67,8 +69,17 @@ public class CarRanYouJob {
                 throw new MyRuntimeException("河北成本管理系统车辆燃油数据没有文件");
             }
             for (Path path : pathList) {
-                singleJob(path);
+                CompletableFuture.runAsync(() -> {
+                    try {
+                        singleJob(path);
+                    } catch (Exception e) {
+                        throw new MyRuntimeException(e);
+                    }
+                }).get(1, TimeUnit.MINUTES);
             }
+        } catch (InterruptedException e) {
+            log.error("线程中断: {}", e.getMessage(), e);
+            Thread.currentThread().interrupt();
         } catch (Exception e) {
             log.error(e.getMessage(), e);
         }

+ 12 - 1
src/main/java/com/nokia/finance/tasks/jobs/car/chengben/CarWeiXiuJob.java

@@ -31,6 +31,8 @@ import java.util.ArrayList;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.TimeUnit;
 import java.util.stream.Stream;
 
 /**
@@ -67,8 +69,17 @@ public class CarWeiXiuJob {
                 throw new MyRuntimeException("河北成本管理系统车辆普通维修数据没有文件");
             }
             for (Path path : pathList) {
-                singleJob(path);
+                CompletableFuture.runAsync(() -> {
+                    try {
+                        singleJob(path);
+                    } catch (Exception e) {
+                        throw new MyRuntimeException(e);
+                    }
+                }).get(1, TimeUnit.MINUTES);
             }
+        } catch (InterruptedException e) {
+            log.error("线程中断: {}", e.getMessage(), e);
+            Thread.currentThread().interrupt();
         } catch (Exception e) {
             log.error(e.getMessage(), e);
         }

+ 12 - 1
src/main/java/com/nokia/finance/tasks/jobs/car/ruixing/CarBaoFeiJob.java

@@ -36,7 +36,9 @@ import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.TimeUnit;
 import java.util.function.Function;
 import java.util.function.Predicate;
 import java.util.stream.Stream;
@@ -75,8 +77,17 @@ public class CarBaoFeiJob {
                 throw new MyRuntimeException("睿行车辆报废月数据没有文件");
             }
             for (Path path : pathList) {
-                singleJob(path);
+                CompletableFuture.runAsync(() -> {
+                    try {
+                        singleJob(path);
+                    } catch (Exception e) {
+                        throw new MyRuntimeException(e);
+                    }
+                }).get(1, TimeUnit.MINUTES);
             }
+        } catch (InterruptedException e) {
+            log.error("线程中断: {}", e.getMessage(), e);
+            Thread.currentThread().interrupt();
         } catch (Exception e) {
             log.error(e.getMessage(), e);
         }

+ 12 - 1
src/main/java/com/nokia/finance/tasks/jobs/car/ruixing/CarBaseDataDayJob.java

@@ -39,7 +39,9 @@ import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.TimeUnit;
 import java.util.function.Function;
 import java.util.function.Predicate;
 import java.util.regex.Matcher;
@@ -80,8 +82,17 @@ public class CarBaseDataDayJob {
                 throw new MyRuntimeException("睿行车辆基本信息日数据没有文件");
             }
             for (Path path : pathList) {
-                singleJob(path);
+                CompletableFuture.runAsync(() -> {
+                    try {
+                        singleJob(path);
+                    } catch (Exception e) {
+                        throw new MyRuntimeException(e);
+                    }
+                }).get(1, TimeUnit.MINUTES);
             }
+        } catch (InterruptedException e) {
+            log.error("线程中断: {}", e.getMessage(), e);
+            Thread.currentThread().interrupt();
         } catch (Exception e) {
             log.error(e.getMessage(), e);
         }

+ 12 - 1
src/main/java/com/nokia/finance/tasks/jobs/car/ruixing/CarLiChengMonthJob.java

@@ -36,7 +36,9 @@ import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.TimeUnit;
 import java.util.function.Function;
 import java.util.function.Predicate;
 import java.util.regex.Matcher;
@@ -77,8 +79,17 @@ public class CarLiChengMonthJob {
                 throw new MyRuntimeException("睿行车辆行驶里程月数据没有文件");
             }
             for (Path path : pathList) {
-                singleJob(path);
+                CompletableFuture.runAsync(() -> {
+                    try {
+                        singleJob(path);
+                    } catch (Exception e) {
+                        throw new MyRuntimeException(e);
+                    }
+                }).get(1, TimeUnit.MINUTES);
             }
+        } catch (InterruptedException e) {
+            log.error("线程中断: {}", e.getMessage(), e);
+            Thread.currentThread().interrupt();
         } catch (Exception e) {
             log.error(e.getMessage(), e);
         }

+ 12 - 1
src/main/java/com/nokia/finance/tasks/jobs/car/ruixing/CarWuDanYongCheJob.java

@@ -36,7 +36,9 @@ import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.TimeUnit;
 import java.util.function.Function;
 import java.util.function.Predicate;
 import java.util.stream.Stream;
@@ -75,8 +77,17 @@ public class CarWuDanYongCheJob {
                 throw new MyRuntimeException("睿行车辆无单用车报警月统计数据没有文件");
             }
             for (Path path : pathList) {
-                singleJob(path);
+                CompletableFuture.runAsync(() -> {
+                    try {
+                        singleJob(path);
+                    } catch (Exception e) {
+                        throw new MyRuntimeException(e);
+                    }
+                }).get(1, TimeUnit.MINUTES);
             }
+        } catch (InterruptedException e) {
+            log.error("线程中断: {}", e.getMessage(), e);
+            Thread.currentThread().interrupt();
         } catch (Exception e) {
             log.error(e.getMessage(), e);
         }

+ 12 - 1
src/main/java/com/nokia/finance/tasks/jobs/car/ruixing/CarYongCheJob.java

@@ -36,6 +36,8 @@ import java.util.ArrayList;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.TimeUnit;
 import java.util.stream.Stream;
 
 /**
@@ -72,8 +74,17 @@ public class CarYongCheJob {
                 throw new MyRuntimeException("睿行车辆用车月统计数据没有文件");
             }
             for (Path path : pathList) {
-                singleJob(path);
+                CompletableFuture.runAsync(() -> {
+                    try {
+                        singleJob(path);
+                    } catch (Exception e) {
+                        throw new MyRuntimeException(e);
+                    }
+                }).get(1, TimeUnit.MINUTES);
             }
+        } catch (InterruptedException e) {
+            log.error("线程中断: {}", e.getMessage(), e);
+            Thread.currentThread().interrupt();
         } catch (Exception e) {
             log.error(e.getMessage(), e);
         }

+ 12 - 1
src/main/java/com/nokia/finance/tasks/jobs/car/ruixing/CarYueJieJob.java

@@ -36,7 +36,9 @@ import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.TimeUnit;
 import java.util.function.Function;
 import java.util.function.Predicate;
 import java.util.stream.Stream;
@@ -75,8 +77,17 @@ public class CarYueJieJob {
                 throw new MyRuntimeException("睿行车辆越界报警日数据没有文件");
             }
             for (Path path : pathList) {
-                singleJob(path);
+                CompletableFuture.runAsync(() -> {
+                    try {
+                        singleJob(path);
+                    } catch (Exception e) {
+                        throw new MyRuntimeException(e);
+                    }
+                }).get(1, TimeUnit.MINUTES);
             }
+        } catch (InterruptedException e) {
+            log.error("线程中断: {}", e.getMessage(), e);
+            Thread.currentThread().interrupt();
         } catch (Exception e) {
             log.error(e.getMessage(), e);
         }

+ 12 - 1
src/main/java/com/nokia/finance/tasks/jobs/house/chengben/HouseBuildingRepairMonthJob.java

@@ -26,6 +26,8 @@ import java.util.ArrayList;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.TimeUnit;
 import java.util.stream.Stream;
 
 /**
@@ -55,8 +57,17 @@ public class HouseBuildingRepairMonthJob {
                 throw new MyRuntimeException("河北成本管理系统自有类房产维修数据没有文件");
             }
             for (Path path : pathList) {
-                singleJob(path);
+                CompletableFuture.runAsync(() -> {
+                    try {
+                        singleJob(path);
+                    } catch (Exception e) {
+                        throw new MyRuntimeException(e);
+                    }
+                }).get(1, TimeUnit.MINUTES);
             }
+        } catch (InterruptedException e) {
+            log.error("线程中断: {}", e.getMessage(), e);
+            Thread.currentThread().interrupt();
         } catch (Exception e) {
             log.error(e.getMessage(), e);
         }