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

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 { CrontabViewModel, CronViewType } from '../data/cronView';
import { initPosition } from '../data/env'; import { initPosition } from '../data/env';
import { AuthDataType, SystemModel } from '../data/system'; import { AuthDataType, SystemModel } from '../data/system';
import SystemService from '../services/system';
export default async () => { export default async () => {
const cronService = Container.get(CronService); const cronService = Container.get(CronService);
const envService = Container.get(EnvService); const envService = Container.get(EnvService);
const dependenceService = Container.get(DependenceService); 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({ CrontabViewModel.findAll({
@ -46,7 +66,9 @@ export default async () => {
{ status: DependenceStatus.queued, log: [] }, { status: DependenceStatus.queued, log: [] },
{ where: { id: docs.map((x) => x.id!) } }, { where: { id: docs.map((x) => x.id!) } },
); );
setTimeout(() => {
dependenceService.installDependenceOneByOne(docs); dependenceService.installDependenceOneByOne(docs);
}, 5000);
}); });
// 初始化时执行一次所有的 ql repo 任务 // 初始化时执行一次所有的 ql repo 任务

View File

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