@whyour/qinglong 0.4.1 → 0.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/docker/Dockerfile
CHANGED
package/package.json
CHANGED
|
@@ -336,7 +336,7 @@ let CronService = class CronService {
|
|
|
336
336
|
await cron_1.CrontabModel.update({ status: cron_1.CrontabStatus.idle, pid: undefined }, { where: { id: ids } });
|
|
337
337
|
}
|
|
338
338
|
async runSingle(cronId) {
|
|
339
|
-
return (0, pLimit_1.
|
|
339
|
+
return (0, pLimit_1.runWithCpuLimit)(() => {
|
|
340
340
|
return new Promise(async (resolve) => {
|
|
341
341
|
const cron = await this.getDb({ id: cronId });
|
|
342
342
|
if (cron.status !== cron_1.CrontabStatus.queued) {
|
|
@@ -95,7 +95,7 @@ let DependenceService = class DependenceService {
|
|
|
95
95
|
}
|
|
96
96
|
installDependenceOneByOne(docs, isInstall = true, force = false) {
|
|
97
97
|
docs.forEach((dep) => {
|
|
98
|
-
this.
|
|
98
|
+
this.installOrUninstallDependency(dep, isInstall, force);
|
|
99
99
|
});
|
|
100
100
|
}
|
|
101
101
|
async reInstall(ids) {
|
|
@@ -120,14 +120,11 @@ let DependenceService = class DependenceService {
|
|
|
120
120
|
const newLog = (doc === null || doc === void 0 ? void 0 : doc.log) ? [...doc.log, log] : [log];
|
|
121
121
|
await dependence_1.DependenceModel.update({ log: newLog }, { where: { id: ids } });
|
|
122
122
|
}
|
|
123
|
-
|
|
124
|
-
|
|
123
|
+
installOrUninstallDependency(dependency, isInstall = true, force = false) {
|
|
124
|
+
const fn = dependency.type === dependence_1.DependenceTypes.linux ? pLimit_1.runOneByOne : pLimit_1.runWithCpuLimit;
|
|
125
|
+
return fn(() => {
|
|
125
126
|
return new Promise(async (resolve) => {
|
|
126
|
-
|
|
127
|
-
resolve(null);
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
const depIds = dependencies.map((x) => x.id);
|
|
127
|
+
const depIds = [dependency.id];
|
|
131
128
|
const status = isInstall
|
|
132
129
|
? dependence_1.DependenceStatus.installing
|
|
133
130
|
: dependence_1.DependenceStatus.removing;
|
|
@@ -135,20 +132,20 @@ let DependenceService = class DependenceService {
|
|
|
135
132
|
const socketMessageType = !force
|
|
136
133
|
? 'installDependence'
|
|
137
134
|
: 'uninstallDependence';
|
|
138
|
-
const
|
|
135
|
+
const depName = dependency.name;
|
|
139
136
|
const depRunCommand = (isInstall
|
|
140
137
|
? dependence_1.InstallDependenceCommandTypes
|
|
141
|
-
: dependence_1.unInstallDependenceCommandTypes)[
|
|
138
|
+
: dependence_1.unInstallDependenceCommandTypes)[dependency.type];
|
|
142
139
|
const actionText = isInstall ? '安装' : '删除';
|
|
143
140
|
const startTime = (0, dayjs_1.default)();
|
|
144
|
-
const message = `开始${actionText}依赖 ${
|
|
141
|
+
const message = `开始${actionText}依赖 ${depName},开始时间 ${startTime.format('YYYY-MM-DD HH:mm:ss')}\n\n`;
|
|
145
142
|
this.sockService.sendMessage({
|
|
146
143
|
type: socketMessageType,
|
|
147
144
|
message,
|
|
148
145
|
references: depIds,
|
|
149
146
|
});
|
|
150
147
|
await this.updateLog(depIds, message);
|
|
151
|
-
const cp = (0, cross_spawn_1.spawn)(`${depRunCommand} ${
|
|
148
|
+
const cp = (0, cross_spawn_1.spawn)(`${depRunCommand} ${depName}`, {
|
|
152
149
|
shell: '/bin/bash',
|
|
153
150
|
});
|
|
154
151
|
cp.stdout.on('data', async (data) => {
|
|
@@ -30,7 +30,7 @@ let ScheduleService = class ScheduleService {
|
|
|
30
30
|
this.maxBuffer = 200 * 1024 * 1024;
|
|
31
31
|
}
|
|
32
32
|
async runTask(command, callbacks = {}, completionTime = 'end') {
|
|
33
|
-
return (0, pLimit_1.
|
|
33
|
+
return (0, pLimit_1.runWithCpuLimit)(() => {
|
|
34
34
|
return new Promise(async (resolve, reject) => {
|
|
35
35
|
var _a, _b, _c;
|
|
36
36
|
try {
|
|
@@ -3,14 +3,21 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.runOneByOne = exports.runWithCpuLimit = void 0;
|
|
7
7
|
const p_limit_1 = __importDefault(require("p-limit"));
|
|
8
8
|
const os_1 = __importDefault(require("os"));
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
const cpuLimit = (0, p_limit_1.default)(os_1.default.cpus().length);
|
|
10
|
+
const oneLimit = (0, p_limit_1.default)(1);
|
|
11
|
+
function runWithCpuLimit(fn) {
|
|
12
|
+
return cpuLimit(() => {
|
|
12
13
|
return fn();
|
|
13
14
|
});
|
|
14
15
|
}
|
|
15
|
-
exports.
|
|
16
|
+
exports.runWithCpuLimit = runWithCpuLimit;
|
|
17
|
+
function runOneByOne(fn) {
|
|
18
|
+
return oneLimit(() => {
|
|
19
|
+
return fn();
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
exports.runOneByOne = runOneByOne;
|
|
16
23
|
//# sourceMappingURL=pLimit.js.map
|
|
@@ -8,7 +8,7 @@ const cross_spawn_1 = require("cross-spawn");
|
|
|
8
8
|
const pLimit_1 = require("./pLimit");
|
|
9
9
|
const logger_1 = __importDefault(require("../loaders/logger"));
|
|
10
10
|
function runCron(cmd) {
|
|
11
|
-
return (0, pLimit_1.
|
|
11
|
+
return (0, pLimit_1.runWithCpuLimit)(() => {
|
|
12
12
|
return new Promise(async (resolve) => {
|
|
13
13
|
logger_1.default.silly('运行命令: ' + cmd);
|
|
14
14
|
const cp = (0, cross_spawn_1.spawn)(cmd, { shell: '/bin/bash' });
|