mirror of
https://github.com/whyour/qinglong.git
synced 2025-05-23 14:56:07 +08:00
修复依赖安装流程
This commit is contained in:
parent
87455cebc0
commit
84828865f7
|
@ -16,7 +16,7 @@ import { Op, where, col as colFn, FindOptions } from 'sequelize';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import { TASK_PREFIX, QL_PREFIX } from '../config/const';
|
import { TASK_PREFIX, QL_PREFIX } from '../config/const';
|
||||||
import cronClient from '../schedule/client';
|
import cronClient from '../schedule/client';
|
||||||
import { runCronWithLimit } from '../shared/pLimit';
|
import { runWithCpuLimit } from '../shared/pLimit';
|
||||||
import { spawn } from 'cross-spawn';
|
import { spawn } from 'cross-spawn';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
|
@ -387,7 +387,7 @@ export default class CronService {
|
||||||
}
|
}
|
||||||
|
|
||||||
private async runSingle(cronId: number): Promise<number> {
|
private async runSingle(cronId: number): Promise<number> {
|
||||||
return runCronWithLimit(() => {
|
return runWithCpuLimit(() => {
|
||||||
return new Promise(async (resolve: any) => {
|
return new Promise(async (resolve: any) => {
|
||||||
const cron = await this.getDb({ id: cronId });
|
const cron = await this.getDb({ id: cronId });
|
||||||
if (cron.status !== CrontabStatus.queued) {
|
if (cron.status !== CrontabStatus.queued) {
|
||||||
|
|
|
@ -14,14 +14,14 @@ import SockService from './sock';
|
||||||
import { FindOptions, Op } from 'sequelize';
|
import { FindOptions, Op } from 'sequelize';
|
||||||
import { concurrentRun } from '../config/util';
|
import { concurrentRun } from '../config/util';
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
import { runCronWithLimit } from '../shared/pLimit';
|
import { runOneByOne, runWithCpuLimit } from '../shared/pLimit';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export default class DependenceService {
|
export default class DependenceService {
|
||||||
constructor(
|
constructor(
|
||||||
@Inject('logger') private logger: winston.Logger,
|
@Inject('logger') private logger: winston.Logger,
|
||||||
private sockService: SockService,
|
private sockService: SockService,
|
||||||
) {}
|
) { }
|
||||||
|
|
||||||
public async create(payloads: Dependence[]): Promise<Dependence[]> {
|
public async create(payloads: Dependence[]): Promise<Dependence[]> {
|
||||||
const tabs = payloads.map((x) => {
|
const tabs = payloads.map((x) => {
|
||||||
|
@ -106,7 +106,7 @@ export default class DependenceService {
|
||||||
force: boolean = false,
|
force: boolean = false,
|
||||||
) {
|
) {
|
||||||
docs.forEach((dep) => {
|
docs.forEach((dep) => {
|
||||||
this.installOrUninstallDependencies([dep], isInstall, force);
|
this.installOrUninstallDependency(dep, isInstall, force);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,19 +142,14 @@ export default class DependenceService {
|
||||||
await DependenceModel.update({ log: newLog }, { where: { id: ids } });
|
await DependenceModel.update({ log: newLog }, { where: { id: ids } });
|
||||||
}
|
}
|
||||||
|
|
||||||
public installOrUninstallDependencies(
|
public installOrUninstallDependency(
|
||||||
dependencies: Dependence[],
|
dependency: Dependence,
|
||||||
isInstall: boolean = true,
|
isInstall: boolean = true,
|
||||||
force: boolean = false,
|
force: boolean = false,
|
||||||
) {
|
) {
|
||||||
return runCronWithLimit(() => {
|
return runOneByOne(() => {
|
||||||
return new Promise(async (resolve) => {
|
return new Promise(async (resolve) => {
|
||||||
if (dependencies.length === 0) {
|
const depIds = [dependency.id!];
|
||||||
resolve(null);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const depIds = dependencies.map((x) => x.id) as number[];
|
|
||||||
const status = isInstall
|
const status = isInstall
|
||||||
? DependenceStatus.installing
|
? DependenceStatus.installing
|
||||||
: DependenceStatus.removing;
|
: DependenceStatus.removing;
|
||||||
|
@ -163,16 +158,16 @@ export default class DependenceService {
|
||||||
const socketMessageType = !force
|
const socketMessageType = !force
|
||||||
? 'installDependence'
|
? 'installDependence'
|
||||||
: 'uninstallDependence';
|
: 'uninstallDependence';
|
||||||
const depNames = dependencies.map((x) => x.name).join(' ');
|
const depName = dependency.name;
|
||||||
const depRunCommand = (
|
const depRunCommand = (
|
||||||
isInstall
|
isInstall
|
||||||
? InstallDependenceCommandTypes
|
? InstallDependenceCommandTypes
|
||||||
: unInstallDependenceCommandTypes
|
: unInstallDependenceCommandTypes
|
||||||
)[dependencies[0].type as any];
|
)[dependency.type as any];
|
||||||
const actionText = isInstall ? '安装' : '删除';
|
const actionText = isInstall ? '安装' : '删除';
|
||||||
const startTime = dayjs();
|
const startTime = dayjs();
|
||||||
|
|
||||||
const message = `开始${actionText}依赖 ${depNames},开始时间 ${startTime.format(
|
const message = `开始${actionText}依赖 ${depName},开始时间 ${startTime.format(
|
||||||
'YYYY-MM-DD HH:mm:ss',
|
'YYYY-MM-DD HH:mm:ss',
|
||||||
)}\n\n`;
|
)}\n\n`;
|
||||||
this.sockService.sendMessage({
|
this.sockService.sendMessage({
|
||||||
|
@ -182,7 +177,7 @@ export default class DependenceService {
|
||||||
});
|
});
|
||||||
await this.updateLog(depIds, message);
|
await this.updateLog(depIds, message);
|
||||||
|
|
||||||
const cp = spawn(`${depRunCommand} ${depNames}`, {
|
const cp = spawn(`${depRunCommand} ${depName}`, {
|
||||||
shell: '/bin/bash',
|
shell: '/bin/bash',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ import {
|
||||||
Task,
|
Task,
|
||||||
} from 'toad-scheduler';
|
} from 'toad-scheduler';
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
import { runCronWithLimit } from '../shared/pLimit';
|
import { runWithCpuLimit } from '../shared/pLimit';
|
||||||
import { spawn } from 'cross-spawn';
|
import { spawn } from 'cross-spawn';
|
||||||
|
|
||||||
interface ScheduleTaskType {
|
interface ScheduleTaskType {
|
||||||
|
@ -49,7 +49,7 @@ export default class ScheduleService {
|
||||||
callbacks: TaskCallbacks = {},
|
callbacks: TaskCallbacks = {},
|
||||||
completionTime: 'start' | 'end' = 'end',
|
completionTime: 'start' | 'end' = 'end',
|
||||||
) {
|
) {
|
||||||
return runCronWithLimit(() => {
|
return runWithCpuLimit(() => {
|
||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
try {
|
try {
|
||||||
const startTime = dayjs();
|
const startTime = dayjs();
|
||||||
|
|
|
@ -1,10 +1,17 @@
|
||||||
import pLimit from "p-limit";
|
import pLimit from "p-limit";
|
||||||
import os from 'os';
|
import os from 'os';
|
||||||
|
|
||||||
const cronLimit = pLimit(os.cpus().length);
|
const cpuLimit = pLimit(os.cpus().length);
|
||||||
|
const oneLimit = pLimit(1);
|
||||||
|
|
||||||
export function runCronWithLimit<T>(fn: () => Promise<T>): Promise<T> {
|
export function runWithCpuLimit<T>(fn: () => Promise<T>): Promise<T> {
|
||||||
return cronLimit(() => {
|
return cpuLimit(() => {
|
||||||
|
return fn();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function runOneByOne<T>(fn: () => Promise<T>): Promise<T> {
|
||||||
|
return oneLimit(() => {
|
||||||
return fn();
|
return fn();
|
||||||
});
|
});
|
||||||
}
|
}
|
|
@ -1,9 +1,9 @@
|
||||||
import { spawn } from 'cross-spawn';
|
import { spawn } from 'cross-spawn';
|
||||||
import { runCronWithLimit } from "./pLimit";
|
import { runWithCpuLimit } from "./pLimit";
|
||||||
import Logger from '../loaders/logger';
|
import Logger from '../loaders/logger';
|
||||||
|
|
||||||
export function runCron(cmd: string): Promise<number> {
|
export function runCron(cmd: string): Promise<number> {
|
||||||
return runCronWithLimit(() => {
|
return runWithCpuLimit(() => {
|
||||||
return new Promise(async (resolve: any) => {
|
return new Promise(async (resolve: any) => {
|
||||||
Logger.silly('运行命令: ' + cmd);
|
Logger.silly('运行命令: ' + cmd);
|
||||||
|
|
||||||
|
|
|
@ -106,7 +106,7 @@ const Setting = () => {
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(true);
|
||||||
const [dataSource, setDataSource] = useState<any[]>([]);
|
const [dataSource, setDataSource] = useState<any[]>([]);
|
||||||
const [isModalVisible, setIsModalVisible] = useState(false);
|
const [isModalVisible, setIsModalVisible] = useState(false);
|
||||||
const [editedApp, setEditedApp] = useState<any>();
|
const [editedApp, setEditedApp] = useState<any>();
|
||||||
|
@ -253,6 +253,12 @@ const Setting = () => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (isDemoEnv) {
|
||||||
|
getApps();
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PageContainer
|
<PageContainer
|
||||||
className="ql-container-wrapper ql-container-wrapper-has-tab ql-setting-container"
|
className="ql-container-wrapper ql-container-wrapper-has-tab ql-setting-container"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user