From 264cd37dd5bb2a3095d447bb952ab11d9214f5f2 Mon Sep 17 00:00:00 2001 From: Jerryplusy Date: Fri, 29 Aug 2025 22:58:05 +0800 Subject: [PATCH] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/system/system.service.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/core/system/system.service.ts b/src/core/system/system.service.ts index 0e3b848..2d92af1 100644 --- a/src/core/system/system.service.ts +++ b/src/core/system/system.service.ts @@ -9,6 +9,7 @@ import * as process from 'node:process'; export class SystemService { private readonly logger = new Logger(SystemService.name); private readonly restartFile: string; + private readonly checkIntervalMs = 60 * 60 * 1000; // 1小时 constructor( @Inject(PathService) @@ -20,6 +21,8 @@ export class SystemService { this.pathService.get('temp'), 'restart.timestamp', ); + + this.startAutoCheckUpdate(); } /** @@ -59,10 +62,24 @@ export class SystemService { * 检查更新 */ async checkUpdate(): Promise { + this.logger.debug('检查系统代码更新..'); const updated = await this.autoUpdateService.checkForUpdates(); if (updated) { this.logger.warn('系统代码已更新,正在重启..'); process.exit(1); } } + + /** + * 启动定时检查更新任务 + */ + private startAutoCheckUpdate() { + setInterval(async () => { + try { + await this.checkUpdate(); + } catch (e) { + this.logger.error(`定时检查更新失败: ${e?.message}`); + } + }, this.checkIntervalMs); + } }