瀏覽代碼

优化数据导出文件清理逻辑

woody 11 月之前
父節點
當前提交
6e98840bd1

+ 4 - 3
framework-export/src/main/java/com/chelvc/framework/export/support/DefaultExportHandler.java

@@ -18,6 +18,7 @@ import javax.servlet.http.HttpServletResponse;
 import com.chelvc.framework.base.context.ApplicationContextHolder;
 import com.chelvc.framework.base.context.ThreadContextHolder;
 import com.chelvc.framework.base.util.HttpUtils;
+import com.chelvc.framework.common.function.Executor;
 import com.chelvc.framework.common.util.AssertUtils;
 import com.chelvc.framework.common.util.ExcelUtils;
 import com.chelvc.framework.common.util.FileUtils;
@@ -127,11 +128,11 @@ public class DefaultExportHandler implements ExportHandler {
         ThreadUtils.run(() -> {
             while (!Thread.currentThread().isInterrupted()) {
                 try {
-                    this.clear();
+                    RedisContextHolder.tryLockAround("exporting:clear:lock", (Executor) this::clear);
                 } catch (Exception e) {
                     log.error("Export file clear failed", e);
                 }
-                ThreadUtils.sleep(60 * 1000);
+                ThreadUtils.sleep(this.duration.toMillis());
             }
         });
     }
@@ -190,7 +191,7 @@ public class DefaultExportHandler implements ExportHandler {
             try {
                 listener.accept(id, volume);
             } catch (Exception e) {
-                log.error("Export listener callback failed", e);
+                log.error("Export listening failed", e);
             }
         });
         return id;