feat: 实现RCU固件升级服务核心功能
- 添加升级服务主逻辑,包括定时触发升级、状态查询和日志记录 - 实现数据库初始化脚本和日志表结构 - 添加PM2部署配置文件 - 实现环境变量配置系统 - 添加API客户端模块处理外部接口调用 - 实现升级状态轮询和超时处理机制 - 添加测试用例验证核心功能
This commit is contained in:
50
src/loggerService.js
Normal file
50
src/loggerService.js
Normal file
@@ -0,0 +1,50 @@
|
||||
const db = require('./db');
|
||||
|
||||
const logHostResult = async (data) => {
|
||||
const query = `
|
||||
INSERT INTO upgrade_log (
|
||||
uuid, start_time, roomtype_id, host_str, filename, status,
|
||||
end_time, file_type, config_version, firmware_version
|
||||
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
|
||||
`;
|
||||
const values = [
|
||||
data.uuid,
|
||||
data.start_time,
|
||||
data.roomtype_id,
|
||||
data.host_str,
|
||||
data.filename,
|
||||
data.status,
|
||||
data.end_time,
|
||||
data.file_type,
|
||||
data.config_version,
|
||||
data.firmware_version
|
||||
];
|
||||
await db.query(query, values);
|
||||
};
|
||||
|
||||
const getUpgradeState = async (key) => {
|
||||
const res = await db.query('SELECT * FROM upgrade_state WHERE state_key = $1', [key]);
|
||||
if (res.rows.length > 0) {
|
||||
return res.rows[0];
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
const updateUpgradeState = async (key, currentRoomtypeIndex, executionCount) => {
|
||||
const query = `
|
||||
INSERT INTO upgrade_state (state_key, current_roomtype_index, execution_count, last_updated)
|
||||
VALUES ($1, $2, $3, NOW())
|
||||
ON CONFLICT (state_key)
|
||||
DO UPDATE SET
|
||||
current_roomtype_index = EXCLUDED.current_roomtype_index,
|
||||
execution_count = EXCLUDED.execution_count,
|
||||
last_updated = NOW();
|
||||
`;
|
||||
await db.query(query, [key, currentRoomtypeIndex, executionCount]);
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
logHostResult,
|
||||
getUpgradeState,
|
||||
updateUpgradeState
|
||||
};
|
||||
Reference in New Issue
Block a user