fix: 修复编译错误,core 模块不能依赖 web-service/parser/core-database

core 模块的 Deploy.java 和 PostExecVerticle.java 直接引用了上层模块的类,
导致编译失败(package does not exist)。

- Deploy.java: 移除对 JDBCPoolInit 和 JsParserExecutor 的显式调用,
  vertx.close() 会级联关闭 Vert.x 创建的资源
- PostExecVerticle.java: 移除缓存定时清理逻辑(不能引用 web-service 的 CacheManager)
- CacheManager: 添加 registerPeriodicCleanup() 静态方法,通过 VertxHolder 注册定时任务
- CacheServiceImpl: static 块中调用 CacheManager.registerPeriodicCleanup(),服务加载时自动注册
This commit is contained in:
yukaidi
2026-05-29 01:08:15 +08:00
parent 77c7d6c5d6
commit 9c3945f45a
4 changed files with 25 additions and 23 deletions

View File

@@ -147,19 +147,6 @@ public final class Deploy {
} catch (Exception e) {
LOGGER.warn("Vert.x close error or timeout", e);
}
// 显式关闭 JDBC 连接池vertx.close 不保证关闭 JDBCPoolInit 管理的 pool
try {
var poolInit = cn.qaiu.db.pool.JDBCPoolInit.instance();
if (poolInit != null) poolInit.close();
} catch (Exception e) {
LOGGER.warn("JDBC pool close error", e);
}
// 显式关闭 JS 解析器 WorkerExecutor 线程池
try {
cn.qaiu.parser.customjs.JsParserExecutor.shutdownExecutor();
} catch (Exception e) {
LOGGER.warn("JsParserExecutor shutdown error", e);
}
}));
//配置保存在共享数据中
var sharedData = vertx.sharedData();

View File

@@ -62,16 +62,6 @@ public class PostExecVerticle extends AbstractVerticle {
LOGGER.info("未找到 AppRun 接口的实现类");
}
// 注册定时清理过期缓存任务(每小时执行一次)
vertx.setPeriodic(3600_000, 3600_000, id -> {
try {
cn.qaiu.lz.common.cache.CacheManager cacheManager = new cn.qaiu.lz.common.cache.CacheManager();
cacheManager.cleanupExpiredCache();
} catch (Exception e) {
LOGGER.warn("定时清理缓存任务跳过(数据库可能未就绪)", e);
}
});
LOGGER.info("PostExecVerticle 执行完成");
startPromise.complete();
}

View File

@@ -225,6 +225,26 @@ public class CacheManager {
return promise.future();
}
/**
* 注册定时清理过期缓存任务(每小时执行一次)
* 应在应用启动后调用
*/
public static void registerPeriodicCleanup() {
try {
io.vertx.core.Vertx vertx = cn.qaiu.vx.core.util.VertxHolder.getVertxInstance();
vertx.setPeriodic(3600_000, 3600_000, id -> {
try {
new CacheManager().cleanupExpiredCache();
} catch (Exception e) {
LOGGER.warn("定时清理缓存任务跳过(数据库可能未就绪)", e);
}
});
LOGGER.info("缓存定时清理任务已注册(每小时执行)");
} catch (Exception e) {
LOGGER.warn("注册缓存定时清理任务失败", e);
}
}
public Future<Map<String, Integer>> getShareKeyTotal(String shareKey) {
String sql = """
SELECT `share_key`, SUM(cache_hit_total) AS hit_total, SUM(api_parser_total) AS parser_total

View File

@@ -29,6 +29,11 @@ public class CacheServiceImpl implements CacheService {
private final CacheManager cacheManager = new CacheManager();
static {
// 服务类加载时注册缓存定时清理任务
CacheManager.registerPeriodicCleanup();
}
private Future<CacheLinkInfo> getAndSaveCachedShareLink(ParserCreate parserCreate) {
// 认证、域名相关(检查是否已经添加过参数,避免重复调用)