boot 任务改为在依赖安装完成后执行

This commit is contained in:
whyour 2025-04-25 23:52:33 +08:00
parent 40a831f3a2
commit 71a7c1b9d3
4 changed files with 29 additions and 13 deletions

View File

@ -17,7 +17,6 @@ async function startServer() {
Logger.debug(`✌️ 后端服务启动成功!`); Logger.debug(`✌️ 后端服务启动成功!`);
console.debug(`✌️ 后端服务启动成功!`); console.debug(`✌️ 后端服务启动成功!`);
process.send?.('ready'); process.send?.('ready');
require('./loaders/bootAfter').default();
}) })
.on('error', (err) => { .on('error', (err) => {
Logger.error(err); Logger.error(err);

View File

@ -68,24 +68,26 @@ export default async () => {
}); });
} }
const installDependencies = () => { const installDependencies = async () => {
// 初始化时安装所有处于安装中,安装成功,安装失败的依赖 const docs = await DependenceModel.findAll({
DependenceModel.findAll({
where: {}, where: {},
order: [ order: [
['type', 'DESC'], ['type', 'DESC'],
['createdAt', 'DESC'], ['createdAt', 'DESC'],
], ],
raw: true, raw: true,
}).then(async (docs) => {
await DependenceModel.update(
{ status: DependenceStatus.queued, log: [] },
{ where: { id: docs.map((x) => x.id!) } },
);
setTimeout(() => {
dependenceService.installDependenceOneByOne(docs);
}, 5000);
}); });
await DependenceModel.update(
{ status: DependenceStatus.queued, log: [] },
{ where: { id: docs.map((x) => x.id!) } },
);
setTimeout(async () => {
await dependenceService.installDependenceOneByOne(docs);
require('./loaders/bootAfter').default();
}, 5000);
}; };
// 初始化更新 linux/python/nodejs 镜像源配置 // 初始化更新 linux/python/nodejs 镜像源配置

View File

@ -132,10 +132,12 @@ export default class DependenceService {
docs: Dependence[], docs: Dependence[],
isInstall: boolean = true, isInstall: boolean = true,
force: boolean = false, force: boolean = false,
) { ): Promise<void> {
docs.forEach((dep) => { docs.forEach((dep) => {
this.installOrUninstallDependency(dep, isInstall, force); this.installOrUninstallDependency(dep, isInstall, force);
}); });
return taskLimit.waitDependencyQueueDone();
} }
public async reInstall(ids: number[]): Promise<Dependence[]> { public async reInstall(ids: number[]): Promise<Dependence[]> {

View File

@ -189,6 +189,19 @@ class TaskLimit {
return this.scriptLimit.add(fn, options); return this.scriptLimit.add(fn, options);
} }
public async waitDependencyQueueDone(): Promise<void> {
if (this.dependenyLimit.size === 0 && this.dependenyLimit.pending === 0) {
return;
}
return new Promise((resolve) => {
const onIdle = () => {
this.dependenyLimit.removeListener('idle', onIdle);
resolve();
};
this.dependenyLimit.on('idle', onIdle);
});
}
public runDependeny<T>( public runDependeny<T>(
dependency: Dependence, dependency: Dependence,
fn: IDependencyFn<T>, fn: IDependencyFn<T>,