feat(processor): 增加数据库连接断开检测与自动恢复机制
- 在 DatabaseManager 中添加 checkConnection 方法用于检测数据库连接状态 - 当数据库连接断开时,自动暂停 Kafka 消费者,防止消息堆积 - 实现每分钟数据库连接检查,连接恢复后自动恢复消费者处理 - 区分数据库连接错误和其他严重错误,连接错误时保留数据等待重试 - 在 .gitignore 中添加 SQL 文件排除
This commit is contained in:
@@ -42,6 +42,20 @@ class DatabaseManager {
|
||||
}
|
||||
}
|
||||
|
||||
async checkConnection() {
|
||||
if (!this.pool) return false;
|
||||
let client;
|
||||
try {
|
||||
client = await this.pool.connect();
|
||||
await client.query('SELECT 1');
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
} finally {
|
||||
if (client) client.release();
|
||||
}
|
||||
}
|
||||
|
||||
async disconnect() {
|
||||
try {
|
||||
this.stopPartitionMaintenance();
|
||||
|
||||
Reference in New Issue
Block a user