自动更新

This commit is contained in:
Jerry 2025-08-29 22:58:05 +08:00
parent d8dcca7a6a
commit 264cd37dd5

View File

@ -9,6 +9,7 @@ import * as process from 'node:process';
export class SystemService { export class SystemService {
private readonly logger = new Logger(SystemService.name); private readonly logger = new Logger(SystemService.name);
private readonly restartFile: string; private readonly restartFile: string;
private readonly checkIntervalMs = 60 * 60 * 1000; // 1小时
constructor( constructor(
@Inject(PathService) @Inject(PathService)
@ -20,6 +21,8 @@ export class SystemService {
this.pathService.get('temp'), this.pathService.get('temp'),
'restart.timestamp', 'restart.timestamp',
); );
this.startAutoCheckUpdate();
} }
/** /**
@ -59,10 +62,24 @@ export class SystemService {
* *
*/ */
async checkUpdate(): Promise<void> { async checkUpdate(): Promise<void> {
this.logger.debug('检查系统代码更新..');
const updated = await this.autoUpdateService.checkForUpdates(); const updated = await this.autoUpdateService.checkForUpdates();
if (updated) { if (updated) {
this.logger.warn('系统代码已更新,正在重启..'); this.logger.warn('系统代码已更新,正在重启..');
process.exit(1); process.exit(1);
} }
} }
/**
*
*/
private startAutoCheckUpdate() {
setInterval(async () => {
try {
await this.checkUpdate();
} catch (e) {
this.logger.error(`定时检查更新失败: ${e?.message}`);
}
}, this.checkIntervalMs);
}
} }