mirror of
https://github.com/crystelf/crystelf-core.git
synced 2025-12-05 10:31:56 +00:00
自动更新
This commit is contained in:
parent
d8dcca7a6a
commit
264cd37dd5
@ -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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user