修复启动时依赖配置未初始化

This commit is contained in:
whyour 2024-01-24 22:55:21 +08:00
parent 0a723318a1
commit 7f3e60423b
2 changed files with 29 additions and 7 deletions

View File

@ -10,11 +10,31 @@ import config from '../config';
import { CrontabViewModel, CronViewType } from '../data/cronView';
import { initPosition } from '../data/env';
import { AuthDataType, SystemModel } from '../data/system';
import SystemService from '../services/system';
export default async () => {
const cronService = Container.get(CronService);
const envService = Container.get(EnvService);
const dependenceService = Container.get(DependenceService);
const systemService = Container.get(SystemService);
// 初始化更新 linux/python/nodejs 镜像源配置
const systemConfig = await systemService.getSystemConfig();
if (systemConfig.info?.pythonMirror) {
systemService.updatePythonMirror({
linuxMirror: systemConfig.info?.linuxMirror,
});
}
if (systemConfig.info?.linuxMirror) {
systemService.updateLinuxMirror({
linuxMirror: systemConfig.info?.linuxMirror,
});
}
if (systemConfig.info?.nodeMirror) {
systemService.updateNodeMirror({
linuxMirror: systemConfig.info?.linuxMirror,
});
}
// 初始化新增默认全部任务视图
CrontabViewModel.findAll({
@ -46,7 +66,9 @@ export default async () => {
{ status: DependenceStatus.queued, log: [] },
{ where: { id: docs.map((x) => x.id!) } },
);
dependenceService.installDependenceOneByOne(docs);
setTimeout(() => {
dependenceService.installDependenceOneByOne(docs);
}, 5000);
});
// 初始化时执行一次所有的 ql repo 任务

View File

@ -126,7 +126,7 @@ export default class SystemService {
return { code: 200, data: info };
}
public async updateNodeMirror(info: SystemModelInfo, res: Response) {
public async updateNodeMirror(info: SystemModelInfo, res?: Response) {
const oDoc = await this.getSystemConfig();
await this.updateAuthDb({
...oDoc,
@ -141,8 +141,8 @@ export default class SystemService {
command,
{
onStart: async (cp) => {
res.setHeader('QL-Task-Pid', `${cp.pid}`);
res.end();
res?.setHeader('QL-Task-Pid', `${cp.pid}`);
res?.end();
},
onEnd: async () => {
this.sockService.sendMessage({
@ -177,7 +177,7 @@ export default class SystemService {
return { code: 200, data: info };
}
public async updateLinuxMirror(info: SystemModelInfo, res: Response) {
public async updateLinuxMirror(info: SystemModelInfo, res?: Response) {
const oDoc = await this.getSystemConfig();
await this.updateAuthDb({
...oDoc,
@ -203,8 +203,8 @@ export default class SystemService {
command,
{
onStart: async (cp) => {
res.setHeader('QL-Task-Pid', `${cp.pid}`);
res.end();
res?.setHeader('QL-Task-Pid', `${cp.pid}`);
res?.end();
},
onEnd: async () => {
this.sockService.sendMessage({