@whyour/qinglong 0.3.2 → 0.4.0

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.
Files changed (173) hide show
  1. package/README-en.md +47 -88
  2. package/README.md +48 -87
  3. package/package.json +5 -1
  4. package/sample/notify.js +19 -9
  5. package/sample/notify.py +89 -47
  6. package/shell/api.sh +15 -15
  7. package/shell/otask.sh +1 -1
  8. package/shell/update.sh +12 -13
  9. package/static/build/api/system.js +1 -2
  10. package/static/build/api/user.js +5 -1
  11. package/static/build/config/serverEnv.js +1 -1
  12. package/static/build/data/dependence.js +1 -1
  13. package/static/build/data/notify.js +2 -0
  14. package/static/build/data/open.js +1 -8
  15. package/static/build/loaders/express.js +1 -9
  16. package/static/build/loaders/initFile.js +24 -6
  17. package/static/build/loaders/sentry.js +7 -1
  18. package/static/build/schedule/addCron.js +2 -2
  19. package/static/build/schedule/health.js +2 -2
  20. package/static/build/services/cron.js +50 -44
  21. package/static/build/services/dependence.js +82 -79
  22. package/static/build/services/env.js +1 -1
  23. package/static/build/services/notify.js +5 -5
  24. package/static/build/services/open.js +1 -1
  25. package/static/build/services/schedule.js +42 -40
  26. package/static/build/services/subscription.js +7 -13
  27. package/static/build/services/system.js +2 -2
  28. package/static/build/shared/pLimit.js +16 -0
  29. package/static/build/shared/runCron.js +29 -0
  30. package/static/dist/{1571.a97c18af.async.js → 1571.68121491.async.js} +3 -3
  31. package/static/dist/{9371.27629d57.async.js → 1654.e06fbac5.async.js} +1 -1
  32. package/static/dist/2260.d9fbd460.async.js +1 -0
  33. package/static/dist/2536.a60b8e3c.async.js +1 -0
  34. package/static/dist/{2618.2d258f44.async.js → 2618.1484edc2.async.js} +2 -2
  35. package/static/dist/2715.80e099e1.async.js +1 -0
  36. package/static/dist/{3490.8aaeafbb.async.js → 3490.8d2d9399.async.js} +1 -1
  37. package/static/dist/3639.58c3a3f1.async.js +5 -0
  38. package/static/dist/3800.5488ae14.async.js +2 -0
  39. package/static/dist/3820.faa46a6a.async.js +1 -0
  40. package/static/dist/4124.8cba8410.async.js +1 -0
  41. package/static/dist/4163.a1d279c3.async.js +1 -0
  42. package/static/dist/4346.5ab6fdc1.async.js +1 -0
  43. package/static/dist/{4378.70f18b85.async.js → 4378.70083a42.async.js} +2 -2
  44. package/static/dist/4491.96ee9a9f.async.js +4 -0
  45. package/static/dist/4804.183d71af.async.js +27 -0
  46. package/static/dist/4925.eca85085.async.js +1 -0
  47. package/static/dist/5008.c612bbdb.async.js +11 -0
  48. package/static/dist/5035.2489750b.async.js +67 -0
  49. package/static/dist/5310.6c4eff46.async.js +1 -0
  50. package/static/dist/5484.826c5ee3.async.js +1 -0
  51. package/static/dist/5969.87aeb075.async.js +1 -0
  52. package/static/dist/6304.51c52839.async.js +1 -0
  53. package/static/dist/6433.69941426.async.js +22 -0
  54. package/static/dist/6661.5cda5ce0.async.js +1 -0
  55. package/static/dist/6805.798ec30a.async.js +1 -0
  56. package/static/dist/{412.7e4d2d42.async.js → 7382.305c10b2.async.js} +2 -2
  57. package/static/dist/{7393.b7603b10.async.js → 7393.d9ed4b3a.async.js} +1 -1
  58. package/static/dist/7567.a224d0a6.async.js +5 -0
  59. package/static/dist/{7742.eec663d7.async.js → 7742.dd8a0112.async.js} +2 -2
  60. package/static/dist/8037.386b415d.async.js +1 -0
  61. package/static/dist/8297.e6ac1ce9.async.js +1 -0
  62. package/static/dist/8432.5bbc2cdd.async.js +1 -0
  63. package/static/dist/858.d51fc4e2.async.js +1 -0
  64. package/static/dist/8612.84caf0a5.async.js +1 -0
  65. package/static/dist/{8966.d92806db.async.js → 8657.805a96f7.async.js} +2 -2
  66. package/static/dist/8844.8525fd2e.async.js +81 -0
  67. package/static/dist/9065.6684b5d0.async.js +1 -0
  68. package/static/dist/921.198cefa6.async.js +6 -0
  69. package/static/dist/{9504.06cb7ea5.async.js → 9504.6d4e29e7.async.js} +1 -1
  70. package/static/dist/9673.18a70227.async.js +3 -0
  71. package/static/dist/986.ab6a48a4.async.js +1 -0
  72. package/static/dist/index.html +1 -1
  73. package/static/dist/layouts__index.285d8505.chunk.css +1 -0
  74. package/static/dist/layouts__index.3db43e0b.async.js +1 -0
  75. package/static/dist/src__pages__404.8794c158.async.js +1 -0
  76. package/static/dist/{src__pages__config__index.b5bde963.async.js → src__pages__config__index.7fb61af5.async.js} +3 -3
  77. package/static/dist/{src__pages__crontab__index.be4295e5.async.js → src__pages__crontab__index.5cfa7d5b.async.js} +2 -2
  78. package/static/dist/src__pages__crontab__logModal.44ad577c.async.js +2 -0
  79. package/static/dist/src__pages__crontab__modal.6d17fdcf.async.js +5 -0
  80. package/static/dist/src__pages__crontab__viewCreateModal.3db14204.async.js +4 -0
  81. package/static/dist/src__pages__crontab__viewManageModal.9f899650.async.js +4 -0
  82. package/static/dist/src__pages__dependence__index.3b140a79.async.js +2 -0
  83. package/static/dist/src__pages__dependence__logModal.e49658d5.async.js +4 -0
  84. package/static/dist/src__pages__dependence__modal.94ff002a.async.js +5 -0
  85. package/static/dist/{src__pages__diff__index.200be0dc.async.js → src__pages__diff__index.240e4991.async.js} +3 -3
  86. package/static/dist/{src__pages__env__editNameModal.9898b16a.async.js → src__pages__env__editNameModal.047bb3ba.async.js} +2 -2
  87. package/static/dist/src__pages__env__index.48602d18.async.js +2 -0
  88. package/static/dist/src__pages__env__modal.8b48ffa4.async.js +5 -0
  89. package/static/dist/src__pages__error__index.c0477141.async.js +4 -0
  90. package/static/dist/{src__pages__initialization__index.bcf87634.chunk.css → src__pages__initialization__index.66819338.chunk.css} +1 -1
  91. package/static/dist/src__pages__initialization__index.978a7f09.async.js +21 -0
  92. package/static/dist/src__pages__log__index.ae245070.async.js +1 -0
  93. package/static/dist/src__pages__login__index.8eb4df8e.async.js +2 -0
  94. package/static/dist/{src__pages__script__editModal.9a8934a1.async.js → src__pages__script__editModal.02b12902.async.js} +2 -2
  95. package/static/dist/{src__pages__script__editNameModal.42003a2f.async.js → src__pages__script__editNameModal.2773cb7b.async.js} +2 -2
  96. package/static/dist/{src__pages__script__index.670d9577.async.js → src__pages__script__index.679510cd.async.js} +3 -3
  97. package/static/dist/{src__pages__script__renameModal.3b9285b0.async.js → src__pages__script__renameModal.ea3b6689.async.js} +2 -2
  98. package/static/dist/{src__pages__script__saveModal.475c369d.async.js → src__pages__script__saveModal.312a0beb.async.js} +2 -2
  99. package/static/dist/{src__pages__script__setting.d41d33ae.async.js → src__pages__script__setting.11abc6ae.async.js} +2 -2
  100. package/static/dist/src__pages__setting__about.1460b7fa.async.js +1 -0
  101. package/static/dist/{src__pages__setting__appModal.4edca962.async.js → src__pages__setting__appModal.74267529.async.js} +2 -2
  102. package/static/dist/src__pages__setting__checkUpdate.ce2e30bb.async.js +4 -0
  103. package/static/dist/src__pages__setting__index.9fcd6dc2.async.js +2 -0
  104. package/static/dist/src__pages__setting__loginLog.0708083b.async.js +18 -0
  105. package/static/dist/src__pages__setting__notification.15a286d0.async.js +21 -0
  106. package/static/dist/src__pages__setting__other.00a69cf4.async.js +1 -0
  107. package/static/dist/src__pages__setting__security.62b6b562.async.js +4 -0
  108. package/static/dist/src__pages__subscription__index.708b6c8f.async.js +2 -0
  109. package/static/dist/src__pages__subscription__logModal.3a1a8e58.async.js +2 -0
  110. package/static/dist/src__pages__subscription__modal.c034f25a.async.js +4 -0
  111. package/static/dist/umi.cb44a99a.js +11 -0
  112. package/version.yaml +10 -5
  113. package/static/dist/1655.37556417.async.js +0 -4
  114. package/static/dist/1766.e0c12c07.async.js +0 -27
  115. package/static/dist/2260.04ae2823.async.js +0 -1
  116. package/static/dist/2715.30714799.async.js +0 -1
  117. package/static/dist/3639.62e1ddf6.async.js +0 -5
  118. package/static/dist/3820.ad340d47.async.js +0 -1
  119. package/static/dist/4011.3a02258a.async.js +0 -22
  120. package/static/dist/4124.6a5a1531.async.js +0 -1
  121. package/static/dist/4163.5180a456.async.js +0 -1
  122. package/static/dist/4180.e830b6e6.async.js +0 -2
  123. package/static/dist/4925.4425d963.async.js +0 -1
  124. package/static/dist/5008.8fcc2d24.async.js +0 -11
  125. package/static/dist/5310.9c3e0c09.async.js +0 -1
  126. package/static/dist/5319.dd84246e.async.js +0 -1
  127. package/static/dist/5484.ac83d6b4.async.js +0 -1
  128. package/static/dist/5544.6baaab99.async.js +0 -81
  129. package/static/dist/6304.613145ef.async.js +0 -1
  130. package/static/dist/6661.f5843bf4.async.js +0 -1
  131. package/static/dist/6794.4c503d6d.async.js +0 -5
  132. package/static/dist/6805.f5be6007.async.js +0 -1
  133. package/static/dist/7461.ed40fa5f.async.js +0 -1
  134. package/static/dist/7466.15597d4f.async.js +0 -1
  135. package/static/dist/7938.4e3377e7.async.js +0 -67
  136. package/static/dist/8037.61d0095e.async.js +0 -1
  137. package/static/dist/8297.3d6c376d.async.js +0 -1
  138. package/static/dist/8352.e0fbb494.async.js +0 -1
  139. package/static/dist/8432.30267db1.async.js +0 -1
  140. package/static/dist/8447.d0f63993.async.js +0 -1
  141. package/static/dist/9065.0806f3e5.async.js +0 -1
  142. package/static/dist/9280.aacaa172.async.js +0 -6
  143. package/static/dist/9673.a1545ea3.async.js +0 -3
  144. package/static/dist/986.c108246f.async.js +0 -1
  145. package/static/dist/layouts__index.3de47467.chunk.css +0 -1
  146. package/static/dist/layouts__index.a6451a2c.async.js +0 -1
  147. package/static/dist/src__pages__404.b5140a4b.async.js +0 -1
  148. package/static/dist/src__pages__crontab__logModal.0f6a4945.async.js +0 -2
  149. package/static/dist/src__pages__crontab__modal.cb176c70.async.js +0 -5
  150. package/static/dist/src__pages__crontab__viewCreateModal.f2b8a69a.async.js +0 -4
  151. package/static/dist/src__pages__crontab__viewManageModal.b86bbb79.async.js +0 -4
  152. package/static/dist/src__pages__dependence__index.c17201d7.async.js +0 -2
  153. package/static/dist/src__pages__dependence__logModal.42c56e18.async.js +0 -4
  154. package/static/dist/src__pages__dependence__modal.58620a62.async.js +0 -5
  155. package/static/dist/src__pages__env__index.c79218f4.async.js +0 -2
  156. package/static/dist/src__pages__env__modal.07f411f1.async.js +0 -5
  157. package/static/dist/src__pages__error__index.2f9d7c50.async.js +0 -4
  158. package/static/dist/src__pages__initialization__index.af82f7e1.async.js +0 -21
  159. package/static/dist/src__pages__log__index.5e63a6b7.async.js +0 -1
  160. package/static/dist/src__pages__login__index.44d624a7.async.js +0 -2
  161. package/static/dist/src__pages__setting__about.7ca2707b.async.js +0 -1
  162. package/static/dist/src__pages__setting__checkUpdate.dd497877.async.js +0 -4
  163. package/static/dist/src__pages__setting__index.4a85066e.async.js +0 -2
  164. package/static/dist/src__pages__setting__loginLog.c8ddd712.async.js +0 -18
  165. package/static/dist/src__pages__setting__notification.e124b7ae.async.js +0 -21
  166. package/static/dist/src__pages__setting__other.a58b5fae.async.js +0 -1
  167. package/static/dist/src__pages__setting__security.aabc2d21.async.js +0 -4
  168. package/static/dist/src__pages__subscription__index.04531731.async.js +0 -2
  169. package/static/dist/src__pages__subscription__logModal.b86a5c9b.async.js +0 -2
  170. package/static/dist/src__pages__subscription__modal.ea198f81.async.js +0 -4
  171. package/static/dist/umi.29bfaff2.js +0 -11
  172. /package/static/dist/{8352.d2d0a2c7.chunk.css → 8612.d2d0a2c7.chunk.css} +0 -0
  173. /package/static/dist/{7394.59dcf306.chunk.css → 9439.59dcf306.chunk.css} +0 -0
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.addCron = void 0;
7
7
  const node_schedule_1 = __importDefault(require("node-schedule"));
8
8
  const data_1 = require("./data");
9
- const child_process_1 = require("child_process");
9
+ const runCron_1 = require("../shared/runCron");
10
10
  const addCron = (call, callback) => {
11
11
  var _a;
12
12
  for (const item of call.request.crons) {
@@ -15,7 +15,7 @@ const addCron = (call, callback) => {
15
15
  (_a = data_1.scheduleStacks.get(id)) === null || _a === void 0 ? void 0 : _a.cancel();
16
16
  }
17
17
  data_1.scheduleStacks.set(id, node_schedule_1.default.scheduleJob(id, schedule, async () => {
18
- (0, child_process_1.exec)(`ID=${id} ${command}`);
18
+ (0, runCron_1.runCron)(`ID=${id} ${command}`);
19
19
  }));
20
20
  }
21
21
  callback(null, null);
@@ -9,13 +9,13 @@ const util_1 = require("../config/util");
9
9
  const check = async (call, callback) => {
10
10
  switch (call.request.service) {
11
11
  case 'cron':
12
- const res = await (0, util_1.promiseExec)(`curl -sf http://localhost:${config_1.default.port}/api/system`);
12
+ const res = await (0, util_1.promiseExec)(`curl -s http://localhost:${config_1.default.port}/api/system`);
13
13
  if (res.includes('200')) {
14
14
  return callback(null, { status: 1 });
15
15
  }
16
16
  const panelErrLog = await (0, util_1.promiseExec)(`tail -n 300 ~/.pm2/logs/panel-error.log`);
17
17
  const scheduleErrLog = await (0, util_1.promiseExec)(`tail -n 300 ~/.pm2/logs/schedule-error.log`);
18
- return callback(new Error(`${scheduleErrLog}\n${panelErrLog}`));
18
+ return callback(new Error(`${scheduleErrLog || ''}\n${panelErrLog || ''}\n${res}`));
19
19
  default:
20
20
  return callback(null, { status: 1 });
21
21
  }
@@ -28,6 +28,8 @@ const sequelize_1 = require("sequelize");
28
28
  const path_1 = __importDefault(require("path"));
29
29
  const const_1 = require("../config/const");
30
30
  const client_1 = __importDefault(require("../schedule/client"));
31
+ const pLimit_1 = require("../shared/pLimit");
32
+ const cross_spawn_1 = require("cross-spawn");
31
33
  let CronService = class CronService {
32
34
  constructor(logger) {
33
35
  this.logger = logger;
@@ -165,13 +167,13 @@ let CronService = class CronService {
165
167
  {
166
168
  [operate2]: [
167
169
  { [operate]: `%${value}%` },
168
- { [operate]: `%${encodeURIComponent(value)}%` },
170
+ { [operate]: `%${encodeURI(value)}%` },
169
171
  ],
170
172
  },
171
173
  {
172
174
  [operate2]: [
173
175
  (0, sequelize_1.where)((0, sequelize_1.col)(property), operate, `%${value}%`),
174
- (0, sequelize_1.where)((0, sequelize_1.col)(property), operate, `%${encodeURIComponent(value)}%`),
176
+ (0, sequelize_1.where)((0, sequelize_1.col)(property), operate, `%${encodeURI(value)}%`),
175
177
  ],
176
178
  },
177
179
  ],
@@ -197,7 +199,7 @@ let CronService = class CronService {
197
199
  q[column] = {
198
200
  [sequelize_1.Op.or]: [
199
201
  { [sequelize_1.Op.like]: `%${textArray[1]}%` },
200
- { [sequelize_1.Op.like]: `%${encodeURIComponent(textArray[1])}%` },
202
+ { [sequelize_1.Op.like]: `%${encodeURI(textArray[1])}%` },
201
203
  ],
202
204
  };
203
205
  break;
@@ -205,7 +207,7 @@ let CronService = class CronService {
205
207
  const reg = {
206
208
  [sequelize_1.Op.or]: [
207
209
  { [sequelize_1.Op.like]: `%${searchText}%` },
208
- { [sequelize_1.Op.like]: `%${encodeURIComponent(searchText)}%` },
210
+ { [sequelize_1.Op.like]: `%${encodeURI(searchText)}%` },
209
211
  ],
210
212
  };
211
213
  q[sequelize_1.Op.or] = [
@@ -315,7 +317,9 @@ let CronService = class CronService {
315
317
  }
316
318
  async run(ids) {
317
319
  await cron_1.CrontabModel.update({ status: cron_1.CrontabStatus.queued }, { where: { id: ids } });
318
- (0, util_1.concurrentRun)(ids.map((id) => async () => await this.runSingle(id)), 10);
320
+ ids.forEach((id) => {
321
+ this.runSingle(id);
322
+ });
319
323
  }
320
324
  async stop(ids) {
321
325
  const docs = await cron_1.CrontabModel.findAll({ where: { id: ids } });
@@ -332,47 +336,49 @@ let CronService = class CronService {
332
336
  await cron_1.CrontabModel.update({ status: cron_1.CrontabStatus.idle, pid: undefined }, { where: { id: ids } });
333
337
  }
334
338
  async runSingle(cronId) {
335
- return new Promise(async (resolve) => {
336
- const cron = await this.getDb({ id: cronId });
337
- if (cron.status !== cron_1.CrontabStatus.queued) {
338
- resolve();
339
- return;
340
- }
341
- let { id, command, log_path } = cron;
342
- const absolutePath = path_1.default.resolve(config_1.default.logPath, `${log_path}`);
343
- const logFileExist = log_path && (await (0, util_1.fileExist)(absolutePath));
344
- this.logger.silly('Running job');
345
- this.logger.silly('ID: ' + id);
346
- this.logger.silly('Original command: ' + command);
347
- let cmdStr = command;
348
- if (!cmdStr.startsWith(const_1.TASK_PREFIX) && !cmdStr.startsWith(const_1.QL_PREFIX)) {
349
- cmdStr = `${const_1.TASK_PREFIX}${cmdStr}`;
350
- }
351
- if (cmdStr.endsWith('.js') ||
352
- cmdStr.endsWith('.py') ||
353
- cmdStr.endsWith('.pyc') ||
354
- cmdStr.endsWith('.sh') ||
355
- cmdStr.endsWith('.ts')) {
356
- cmdStr = `${cmdStr} now`;
357
- }
358
- const cp = (0, child_process_1.spawn)(`ID=${id} ${cmdStr}`, { shell: '/bin/bash' });
359
- await cron_1.CrontabModel.update({ status: cron_1.CrontabStatus.running, pid: cp.pid }, { where: { id } });
360
- cp.stderr.on('data', (data) => {
361
- if (logFileExist) {
362
- fs_1.default.appendFileSync(`${absolutePath}`, `${data.toString()}`);
339
+ return (0, pLimit_1.runCronWithLimit)(() => {
340
+ return new Promise(async (resolve) => {
341
+ const cron = await this.getDb({ id: cronId });
342
+ if (cron.status !== cron_1.CrontabStatus.queued) {
343
+ resolve();
344
+ return;
363
345
  }
364
- });
365
- cp.on('error', (err) => {
366
- if (logFileExist) {
367
- fs_1.default.appendFileSync(`${absolutePath}`, `${JSON.stringify(err)}`);
346
+ let { id, command, log_path } = cron;
347
+ const absolutePath = path_1.default.resolve(config_1.default.logPath, `${log_path}`);
348
+ const logFileExist = log_path && (await (0, util_1.fileExist)(absolutePath));
349
+ this.logger.silly('Running job');
350
+ this.logger.silly('ID: ' + id);
351
+ this.logger.silly('Original command: ' + command);
352
+ let cmdStr = command;
353
+ if (!cmdStr.startsWith(const_1.TASK_PREFIX) && !cmdStr.startsWith(const_1.QL_PREFIX)) {
354
+ cmdStr = `${const_1.TASK_PREFIX}${cmdStr}`;
368
355
  }
369
- });
370
- cp.on('exit', async (code, signal) => {
371
- this.logger.info(`任务 ${command} 进程id: ${cp.pid} 退出,退出码 ${code}`);
372
- });
373
- cp.on('close', async (code) => {
374
- await cron_1.CrontabModel.update({ status: cron_1.CrontabStatus.idle, pid: undefined }, { where: { id } });
375
- resolve();
356
+ if (cmdStr.endsWith('.js') ||
357
+ cmdStr.endsWith('.py') ||
358
+ cmdStr.endsWith('.pyc') ||
359
+ cmdStr.endsWith('.sh') ||
360
+ cmdStr.endsWith('.ts')) {
361
+ cmdStr = `${cmdStr} now`;
362
+ }
363
+ const cp = (0, cross_spawn_1.spawn)(`ID=${id} ${cmdStr}`, { shell: '/bin/bash' });
364
+ await cron_1.CrontabModel.update({ status: cron_1.CrontabStatus.running, pid: cp.pid }, { where: { id } });
365
+ cp.stderr.on('data', (data) => {
366
+ if (logFileExist) {
367
+ fs_1.default.appendFileSync(`${absolutePath}`, `${data.toString()}`);
368
+ }
369
+ });
370
+ cp.on('error', (err) => {
371
+ if (logFileExist) {
372
+ fs_1.default.appendFileSync(`${absolutePath}`, `${JSON.stringify(err)}`);
373
+ }
374
+ });
375
+ cp.on('exit', async (code, signal) => {
376
+ this.logger.info(`任务 ${command} 进程id: ${cp.pid} 退出,退出码 ${code}`);
377
+ });
378
+ cp.on('close', async (code) => {
379
+ await cron_1.CrontabModel.update({ status: cron_1.CrontabStatus.idle, pid: undefined }, { where: { id } });
380
+ resolve();
381
+ });
376
382
  });
377
383
  });
378
384
  }
@@ -29,11 +29,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
29
29
  const typedi_1 = require("typedi");
30
30
  const winston_1 = __importDefault(require("winston"));
31
31
  const dependence_1 = require("../data/dependence");
32
- const child_process_1 = require("child_process");
32
+ const cross_spawn_1 = require("cross-spawn");
33
33
  const sock_1 = __importDefault(require("./sock"));
34
34
  const sequelize_1 = require("sequelize");
35
- const util_1 = require("../config/util");
36
35
  const dayjs_1 = __importDefault(require("dayjs"));
36
+ const pLimit_1 = require("../shared/pLimit");
37
37
  let DependenceService = class DependenceService {
38
38
  constructor(logger, sockService) {
39
39
  this.logger = logger;
@@ -76,7 +76,7 @@ let DependenceService = class DependenceService {
76
76
  async dependencies({ searchValue, type }, sort = { position: -1 }, query = {}) {
77
77
  let condition = Object.assign(Object.assign({}, query), { type: dependence_1.DependenceTypes[type] });
78
78
  if (searchValue) {
79
- const encodeText = encodeURIComponent(searchValue);
79
+ const encodeText = encodeURI(searchValue);
80
80
  const reg = {
81
81
  [sequelize_1.Op.or]: [
82
82
  { [sequelize_1.Op.like]: `%${searchValue}%` },
@@ -94,13 +94,9 @@ let DependenceService = class DependenceService {
94
94
  }
95
95
  }
96
96
  installDependenceOneByOne(docs, isInstall = true, force = false) {
97
- (0, util_1.concurrentRun)(docs.map((dep) => async () => {
98
- const status = isInstall
99
- ? dependence_1.DependenceStatus.installing
100
- : dependence_1.DependenceStatus.removing;
101
- await dependence_1.DependenceModel.update({ status }, { where: { id: dep.id } });
102
- return await this.installOrUninstallDependencies([dep], isInstall, force);
103
- }), 1);
97
+ docs.forEach((dep) => {
98
+ this.installOrUninstallDependencies([dep], isInstall, force);
99
+ });
104
100
  }
105
101
  async reInstall(ids) {
106
102
  await dependence_1.DependenceModel.update({ status: dependence_1.DependenceStatus.queued, log: [] }, { where: { id: ids } });
@@ -125,82 +121,89 @@ let DependenceService = class DependenceService {
125
121
  await dependence_1.DependenceModel.update({ log: newLog }, { where: { id: ids } });
126
122
  }
127
123
  installOrUninstallDependencies(dependencies, isInstall = true, force = false) {
128
- return new Promise(async (resolve) => {
129
- if (dependencies.length === 0) {
130
- resolve(null);
131
- return;
132
- }
133
- const socketMessageType = !force
134
- ? 'installDependence'
135
- : 'uninstallDependence';
136
- const depNames = dependencies.map((x) => x.name).join(' ');
137
- const depRunCommand = (isInstall
138
- ? dependence_1.InstallDependenceCommandTypes
139
- : dependence_1.unInstallDependenceCommandTypes)[dependencies[0].type];
140
- const actionText = isInstall ? '安装' : '删除';
141
- const depIds = dependencies.map((x) => x.id);
142
- const startTime = (0, dayjs_1.default)();
143
- const message = `开始${actionText}依赖 ${depNames},开始时间 ${startTime.format('YYYY-MM-DD HH:mm:ss')}\n\n`;
144
- this.sockService.sendMessage({
145
- type: socketMessageType,
146
- message,
147
- references: depIds,
148
- });
149
- await this.updateLog(depIds, message);
150
- const cp = (0, child_process_1.spawn)(`${depRunCommand} ${depNames}`, { shell: '/bin/bash' });
151
- cp.stdout.on('data', async (data) => {
124
+ return (0, pLimit_1.runCronWithLimit)(() => {
125
+ return new Promise(async (resolve) => {
126
+ if (dependencies.length === 0) {
127
+ resolve(null);
128
+ return;
129
+ }
130
+ const depIds = dependencies.map((x) => x.id);
131
+ const status = isInstall
132
+ ? dependence_1.DependenceStatus.installing
133
+ : dependence_1.DependenceStatus.removing;
134
+ await dependence_1.DependenceModel.update({ status }, { where: { id: depIds } });
135
+ const socketMessageType = !force
136
+ ? 'installDependence'
137
+ : 'uninstallDependence';
138
+ const depNames = dependencies.map((x) => x.name).join(' ');
139
+ const depRunCommand = (isInstall
140
+ ? dependence_1.InstallDependenceCommandTypes
141
+ : dependence_1.unInstallDependenceCommandTypes)[dependencies[0].type];
142
+ const actionText = isInstall ? '安装' : '删除';
143
+ const startTime = (0, dayjs_1.default)();
144
+ const message = `开始${actionText}依赖 ${depNames},开始时间 ${startTime.format('YYYY-MM-DD HH:mm:ss')}\n\n`;
152
145
  this.sockService.sendMessage({
153
146
  type: socketMessageType,
154
- message: data.toString(),
147
+ message,
155
148
  references: depIds,
156
149
  });
157
- await this.updateLog(depIds, data.toString());
158
- });
159
- cp.stderr.on('data', async (data) => {
160
- this.sockService.sendMessage({
161
- type: socketMessageType,
162
- message: data.toString(),
163
- references: depIds,
150
+ await this.updateLog(depIds, message);
151
+ const cp = (0, cross_spawn_1.spawn)(`${depRunCommand} ${depNames}`, {
152
+ shell: '/bin/bash',
164
153
  });
165
- await this.updateLog(depIds, data.toString());
166
- });
167
- cp.on('error', async (err) => {
168
- this.sockService.sendMessage({
169
- type: socketMessageType,
170
- message: JSON.stringify(err),
171
- references: depIds,
154
+ cp.stdout.on('data', async (data) => {
155
+ this.sockService.sendMessage({
156
+ type: socketMessageType,
157
+ message: data.toString(),
158
+ references: depIds,
159
+ });
160
+ await this.updateLog(depIds, data.toString());
172
161
  });
173
- await this.updateLog(depIds, JSON.stringify(err));
174
- resolve(null);
175
- });
176
- cp.on('close', async (code) => {
177
- const endTime = (0, dayjs_1.default)();
178
- const isSucceed = code === 0;
179
- const resultText = isSucceed ? '成功' : '失败';
180
- const message = `\n依赖${actionText}${resultText},结束时间 ${endTime.format('YYYY-MM-DD HH:mm:ss')},耗时 ${endTime.diff(startTime, 'second')} 秒`;
181
- this.sockService.sendMessage({
182
- type: socketMessageType,
183
- message,
184
- references: depIds,
162
+ cp.stderr.on('data', async (data) => {
163
+ this.sockService.sendMessage({
164
+ type: socketMessageType,
165
+ message: data.toString(),
166
+ references: depIds,
167
+ });
168
+ await this.updateLog(depIds, data.toString());
169
+ });
170
+ cp.on('error', async (err) => {
171
+ this.sockService.sendMessage({
172
+ type: socketMessageType,
173
+ message: JSON.stringify(err),
174
+ references: depIds,
175
+ });
176
+ await this.updateLog(depIds, JSON.stringify(err));
177
+ });
178
+ cp.on('close', async (code) => {
179
+ const endTime = (0, dayjs_1.default)();
180
+ const isSucceed = code === 0;
181
+ const resultText = isSucceed ? '成功' : '失败';
182
+ const message = `\n依赖${actionText}${resultText},结束时间 ${endTime.format('YYYY-MM-DD HH:mm:ss')},耗时 ${endTime.diff(startTime, 'second')} 秒`;
183
+ this.sockService.sendMessage({
184
+ type: socketMessageType,
185
+ message,
186
+ references: depIds,
187
+ });
188
+ await this.updateLog(depIds, message);
189
+ let status = null;
190
+ if (isSucceed) {
191
+ status = isInstall
192
+ ? dependence_1.DependenceStatus.installed
193
+ : dependence_1.DependenceStatus.removed;
194
+ }
195
+ else {
196
+ status = isInstall
197
+ ? dependence_1.DependenceStatus.installFailed
198
+ : dependence_1.DependenceStatus.removeFailed;
199
+ }
200
+ await dependence_1.DependenceModel.update({ status }, { where: { id: depIds } });
201
+ // 如果删除依赖成功或者强制删除
202
+ if ((isSucceed || force) && !isInstall) {
203
+ this.removeDb(depIds);
204
+ }
205
+ resolve(null);
185
206
  });
186
- await this.updateLog(depIds, message);
187
- let status = null;
188
- if (isSucceed) {
189
- status = isInstall
190
- ? dependence_1.DependenceStatus.installed
191
- : dependence_1.DependenceStatus.removed;
192
- }
193
- else {
194
- status = isInstall
195
- ? dependence_1.DependenceStatus.installFailed
196
- : dependence_1.DependenceStatus.removeFailed;
197
- }
198
- await dependence_1.DependenceModel.update({ status }, { where: { id: depIds } });
199
- // 如果删除依赖成功或者强制删除
200
- if ((isSucceed || force) && !isInstall) {
201
- this.removeDb(depIds);
202
- }
203
- resolve(null);
204
207
  });
205
208
  });
206
209
  }
@@ -130,7 +130,7 @@ let EnvService = class EnvService {
130
130
  async envs(searchText = '', query = {}) {
131
131
  let condition = Object.assign({}, query);
132
132
  if (searchText) {
133
- const encodeText = encodeURIComponent(searchText);
133
+ const encodeText = encodeURI(searchText);
134
134
  const reg = {
135
135
  [sequelize_1.Op.or]: [
136
136
  { [sequelize_1.Op.like]: `%${searchText}%` },
@@ -270,8 +270,8 @@ let NotificationService = class NotificationService {
270
270
  }
271
271
  }
272
272
  async weWorkBot() {
273
- const { weWorkBotKey } = this.params;
274
- const url = `https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=${weWorkBotKey}`;
273
+ const { weWorkBotKey, weWorkOrigin = 'https://qyapi.weixin.qq.com' } = this.params;
274
+ const url = `${weWorkOrigin}/cgi-bin/webhook/send?key=${weWorkBotKey}`;
275
275
  try {
276
276
  const res = await got_1.default
277
277
  .post(url, Object.assign(Object.assign({}, this.gotOption), { json: {
@@ -293,9 +293,9 @@ let NotificationService = class NotificationService {
293
293
  }
294
294
  }
295
295
  async weWorkApp() {
296
- const { weWorkAppKey } = this.params;
296
+ const { weWorkAppKey, weWorkOrigin = 'https://qyapi.weixin.qq.com' } = this.params;
297
297
  const [corpid, corpsecret, touser, agentid, thumb_media_id = '1'] = weWorkAppKey.split(',');
298
- const url = `https://qyapi.weixin.qq.com/cgi-bin/gettoken`;
298
+ const url = `${weWorkOrigin}/cgi-bin/gettoken`;
299
299
  const tokenRes = await got_1.default
300
300
  .post(url, Object.assign(Object.assign({}, this.gotOption), { json: {
301
301
  corpid,
@@ -340,7 +340,7 @@ let NotificationService = class NotificationService {
340
340
  }
341
341
  try {
342
342
  const res = await got_1.default
343
- .post(`https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=${tokenRes.access_token}`, Object.assign(Object.assign({}, this.gotOption), { json: Object.assign({ touser,
343
+ .post(`${weWorkOrigin}/cgi-bin/message/send?access_token=${tokenRes.access_token}`, Object.assign(Object.assign({}, this.gotOption), { json: Object.assign({ touser,
344
344
  agentid, safe: '0' }, options) }))
345
345
  .json();
346
346
  if (res.errcode === 0) {
@@ -78,7 +78,7 @@ let OpenService = class OpenService {
78
78
  async list(searchText = '', sort = {}, query = {}) {
79
79
  let condition = Object.assign({}, query);
80
80
  if (searchText) {
81
- const encodeText = encodeURIComponent(searchText);
81
+ const encodeText = encodeURI(searchText);
82
82
  const reg = {
83
83
  [sequelize_1.Op.or]: [
84
84
  { [sequelize_1.Op.like]: `%${searchText}%` },
@@ -18,9 +18,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
18
18
  const typedi_1 = require("typedi");
19
19
  const winston_1 = __importDefault(require("winston"));
20
20
  const node_schedule_1 = __importDefault(require("node-schedule"));
21
- const child_process_1 = require("child_process");
22
21
  const toad_scheduler_1 = require("toad-scheduler");
23
22
  const dayjs_1 = __importDefault(require("dayjs"));
23
+ const pLimit_1 = require("../shared/pLimit");
24
+ const cross_spawn_1 = require("cross-spawn");
24
25
  let ScheduleService = class ScheduleService {
25
26
  constructor(logger) {
26
27
  this.logger = logger;
@@ -29,53 +30,54 @@ let ScheduleService = class ScheduleService {
29
30
  this.maxBuffer = 200 * 1024 * 1024;
30
31
  }
31
32
  async runTask(command, callbacks = {}, completionTime = 'end') {
32
- return new Promise(async (resolve, reject) => {
33
- var _a, _b, _c;
34
- try {
35
- const startTime = (0, dayjs_1.default)();
36
- await ((_a = callbacks.onBefore) === null || _a === void 0 ? void 0 : _a.call(callbacks, startTime));
37
- const cp = (0, child_process_1.spawn)(command, { shell: '/bin/bash' });
38
- // TODO:
39
- (_b = callbacks.onStart) === null || _b === void 0 ? void 0 : _b.call(callbacks, cp, startTime);
40
- completionTime === 'start' && resolve(cp.pid);
41
- cp.stdout.on('data', async (data) => {
42
- var _a;
43
- await ((_a = callbacks.onLog) === null || _a === void 0 ? void 0 : _a.call(callbacks, data.toString()));
44
- });
45
- cp.stderr.on('data', async (data) => {
46
- var _a;
47
- this.logger.info('[执行任务失败] %s,时间:%s, 错误信息:%j', command, new Date().toLocaleString(), data.toString());
48
- await ((_a = callbacks.onError) === null || _a === void 0 ? void 0 : _a.call(callbacks, data.toString()));
49
- });
50
- cp.on('error', async (err) => {
51
- var _a;
52
- this.logger.error('[创建任务失败] %s,时间:%s, 错误信息:%j', command, new Date().toLocaleString(), err);
53
- await ((_a = callbacks.onError) === null || _a === void 0 ? void 0 : _a.call(callbacks, JSON.stringify(err)));
54
- });
55
- cp.on('exit', async (code, signal) => {
56
- this.logger.info(`[任务退出] ${command} 进程id: ${cp.pid},退出码 ${code}`);
57
- });
58
- cp.on('close', async (code) => {
59
- var _a;
60
- const endTime = (0, dayjs_1.default)();
61
- await ((_a = callbacks.onEnd) === null || _a === void 0 ? void 0 : _a.call(callbacks, cp, endTime, endTime.diff(startTime, 'seconds')));
62
- resolve(null);
63
- });
64
- }
65
- catch (error) {
66
- await this.logger.error('执行任务%s失败,时间:%s, 错误信息:%j', command, new Date().toLocaleString(), error);
67
- await ((_c = callbacks.onError) === null || _c === void 0 ? void 0 : _c.call(callbacks, JSON.stringify(error)));
68
- }
33
+ return (0, pLimit_1.runCronWithLimit)(() => {
34
+ return new Promise(async (resolve, reject) => {
35
+ var _a, _b, _c;
36
+ try {
37
+ const startTime = (0, dayjs_1.default)();
38
+ await ((_a = callbacks.onBefore) === null || _a === void 0 ? void 0 : _a.call(callbacks, startTime));
39
+ const cp = (0, cross_spawn_1.spawn)(command, { shell: '/bin/bash' });
40
+ (_b = callbacks.onStart) === null || _b === void 0 ? void 0 : _b.call(callbacks, cp, startTime);
41
+ completionTime === 'start' && resolve(cp.pid);
42
+ cp.stdout.on('data', async (data) => {
43
+ var _a;
44
+ await ((_a = callbacks.onLog) === null || _a === void 0 ? void 0 : _a.call(callbacks, data.toString()));
45
+ });
46
+ cp.stderr.on('data', async (data) => {
47
+ var _a;
48
+ this.logger.info('[执行任务失败] %s,时间:%s, 错误信息:%j', command, new Date().toLocaleString(), data.toString());
49
+ await ((_a = callbacks.onError) === null || _a === void 0 ? void 0 : _a.call(callbacks, data.toString()));
50
+ });
51
+ cp.on('error', async (err) => {
52
+ var _a;
53
+ this.logger.error('[创建任务失败] %s,时间:%s, 错误信息:%j', command, new Date().toLocaleString(), err);
54
+ await ((_a = callbacks.onError) === null || _a === void 0 ? void 0 : _a.call(callbacks, JSON.stringify(err)));
55
+ });
56
+ cp.on('exit', async (code, signal) => {
57
+ this.logger.info(`[任务退出] ${command} 进程id: ${cp.pid},退出码 ${code}`);
58
+ });
59
+ cp.on('close', async (code) => {
60
+ var _a;
61
+ const endTime = (0, dayjs_1.default)();
62
+ await ((_a = callbacks.onEnd) === null || _a === void 0 ? void 0 : _a.call(callbacks, cp, endTime, endTime.diff(startTime, 'seconds')));
63
+ resolve(null);
64
+ });
65
+ }
66
+ catch (error) {
67
+ await this.logger.error('执行任务%s失败,时间:%s, 错误信息:%j', command, new Date().toLocaleString(), error);
68
+ await ((_c = callbacks.onError) === null || _c === void 0 ? void 0 : _c.call(callbacks, JSON.stringify(error)));
69
+ }
70
+ });
69
71
  });
70
72
  }
71
73
  async createCronTask({ id = 0, command, name, schedule = '' }, callbacks, runImmediately = false) {
72
74
  const _id = this.formatId(id);
73
75
  this.logger.info('[创建cron任务],任务ID: %s,cron: %s,任务名: %s,执行命令: %s', _id, schedule, name, command);
74
76
  this.scheduleStacks.set(_id, node_schedule_1.default.scheduleJob(_id, schedule, async () => {
75
- await this.runTask(command, callbacks);
77
+ this.runTask(command, callbacks);
76
78
  }));
77
79
  if (runImmediately) {
78
- await this.runTask(command, callbacks);
80
+ this.runTask(command, callbacks);
79
81
  }
80
82
  }
81
83
  async cancelCronTask({ id = 0, name }) {
@@ -19,7 +19,6 @@ const typedi_1 = require("typedi");
19
19
  const winston_1 = __importDefault(require("winston"));
20
20
  const config_1 = __importDefault(require("../config"));
21
21
  const subscription_1 = require("../data/subscription");
22
- const child_process_1 = require("child_process");
23
22
  const fs_1 = __importDefault(require("fs"));
24
23
  const util_1 = require("../config/util");
25
24
  const fs_2 = require("fs");
@@ -44,7 +43,7 @@ let SubscriptionService = class SubscriptionService {
44
43
  const reg = {
45
44
  [sequelize_1.Op.or]: [
46
45
  { [sequelize_1.Op.like]: `%${searchText}%` },
47
- { [sequelize_1.Op.like]: `%${encodeURIComponent(searchText)}%` },
46
+ { [sequelize_1.Op.like]: `%${encodeURI(searchText)}%` },
48
47
  ],
49
48
  };
50
49
  query = {
@@ -91,13 +90,6 @@ let SubscriptionService = class SubscriptionService {
91
90
  const docs = await subscription_1.SubscriptionModel.findAll();
92
91
  this.sshKeyService.setSshConfig(docs);
93
92
  }
94
- async promiseExec(command) {
95
- return new Promise((resolve, reject) => {
96
- (0, child_process_1.exec)(command, { maxBuffer: 200 * 1024 * 1024, encoding: 'utf8' }, (err, stdout, stderr) => {
97
- resolve(stdout || stderr || JSON.stringify(err));
98
- });
99
- });
100
- }
101
93
  taskCallbacks(doc) {
102
94
  return {
103
95
  onBefore: async (startTime) => {
@@ -113,7 +105,7 @@ let SubscriptionService = class SubscriptionService {
113
105
  try {
114
106
  if (doc.sub_before) {
115
107
  fs_1.default.appendFileSync(absolutePath, `\n## 执行before命令...\n\n`);
116
- beforeStr = await this.promiseExec(doc.sub_before);
108
+ beforeStr = await (0, util_1.promiseExec)(doc.sub_before);
117
109
  }
118
110
  }
119
111
  catch (error) {
@@ -137,7 +129,7 @@ let SubscriptionService = class SubscriptionService {
137
129
  try {
138
130
  if (sub.sub_after) {
139
131
  fs_1.default.appendFileSync(absolutePath, `\n\n## 执行after命令...\n\n`);
140
- afterStr = await this.promiseExec(sub.sub_after);
132
+ afterStr = await (0, util_1.promiseExec)(sub.sub_after);
141
133
  }
142
134
  }
143
135
  catch (error) {
@@ -215,7 +207,9 @@ let SubscriptionService = class SubscriptionService {
215
207
  }
216
208
  async run(ids) {
217
209
  await subscription_1.SubscriptionModel.update({ status: subscription_1.SubscriptionStatus.queued }, { where: { id: ids } });
218
- (0, util_1.concurrentRun)(ids.map((id) => async () => await this.runSingle(id)), 10);
210
+ ids.forEach((id) => {
211
+ this.runSingle(id);
212
+ });
219
213
  }
220
214
  async stop(ids) {
221
215
  const docs = await subscription_1.SubscriptionModel.findAll({ where: { id: ids } });
@@ -239,7 +233,7 @@ let SubscriptionService = class SubscriptionService {
239
233
  return;
240
234
  }
241
235
  const command = (0, subscription_2.formatCommand)(subscription);
242
- await this.scheduleService.runTask(command, this.taskCallbacks(subscription));
236
+ this.scheduleService.runTask(command, this.taskCallbacks(subscription));
243
237
  }
244
238
  async disabled(ids) {
245
239
  await subscription_1.SubscriptionModel.update({ is_disabled: 1 }, { where: { id: ids } });
@@ -21,7 +21,7 @@ const config_1 = __importDefault(require("../config"));
21
21
  const auth_1 = require("../data/auth");
22
22
  const notify_1 = __importDefault(require("./notify"));
23
23
  const schedule_1 = __importDefault(require("./schedule"));
24
- const child_process_1 = require("child_process");
24
+ const cross_spawn_1 = require("cross-spawn");
25
25
  const sock_1 = __importDefault(require("./sock"));
26
26
  const got_1 = __importDefault(require("got"));
27
27
  const util_1 = require("../config/util");
@@ -123,7 +123,7 @@ let SystemService = class SystemService {
123
123
  return false;
124
124
  }
125
125
  async updateSystem() {
126
- const cp = (0, child_process_1.spawn)('ql -l update', { shell: '/bin/bash' });
126
+ const cp = (0, cross_spawn_1.spawn)('ql -l update', { shell: '/bin/bash' });
127
127
  cp.stdout.on('data', (data) => {
128
128
  this.sockService.sendMessage({
129
129
  type: 'updateSystemVersion',
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.runCronWithLimit = void 0;
7
+ const p_limit_1 = __importDefault(require("p-limit"));
8
+ const os_1 = __importDefault(require("os"));
9
+ const cronLimit = (0, p_limit_1.default)(os_1.default.cpus().length);
10
+ function runCronWithLimit(fn) {
11
+ return cronLimit(() => {
12
+ return fn();
13
+ });
14
+ }
15
+ exports.runCronWithLimit = runCronWithLimit;
16
+ //# sourceMappingURL=pLimit.js.map