@whyour/qinglong 2.21.0 → 2.22.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 (279) hide show
  1. package/.dockerignore +13 -0
  2. package/.env.example +7 -0
  3. package/AGENTS.md +2 -2
  4. package/README-en.md +24 -0
  5. package/README.md +24 -0
  6. package/back/protos/api.proto +9 -1
  7. package/back/protos/cron.proto +4 -1
  8. package/deploy/kubernetes/README.md +81 -0
  9. package/deploy/kubernetes/base/kustomization.yaml +5 -0
  10. package/deploy/kubernetes/base/qinglong.yaml +95 -0
  11. package/deploy/kubernetes/overlays/example/kustomization.yaml +10 -0
  12. package/docker/Dockerfile +31 -12
  13. package/docker/Dockerfile.310 +31 -12
  14. package/docker/Dockerfile.debian +22 -14
  15. package/docker/Dockerfile.debian310 +24 -14
  16. package/docker/build-manifest.cjs +28 -0
  17. package/docker/verify-build.cjs +49 -0
  18. package/docs/releases/2.22.0-validation.md +49 -0
  19. package/docs/releases/2.22.0.md +54 -0
  20. package/ecosystem.config.js +10 -1
  21. package/package.json +11 -6
  22. package/sample/config.sample.sh +17 -2
  23. package/sample/notify.js +118 -0
  24. package/sample/notify.py +93 -0
  25. package/scripts/benchmark-execution.cjs +96 -0
  26. package/scripts/write-build-info.cjs +27 -0
  27. package/shell/api.sh +41 -14
  28. package/shell/check.sh +59 -19
  29. package/shell/lang/en.sh +6 -0
  30. package/shell/lang/zh.sh +6 -0
  31. package/shell/node_path_cache.sh +128 -0
  32. package/shell/otask.sh +10 -1
  33. package/shell/preload/sitecustomize.js +5 -1
  34. package/shell/share.sh +26 -9
  35. package/shell/start.sh +6 -3
  36. package/shell/task.sh +13 -3
  37. package/shell/update.sh +65 -4
  38. package/static/build/api/clientIp.js +42 -0
  39. package/static/build/api/config.js +8 -16
  40. package/static/build/api/cron.js +39 -3
  41. package/static/build/api/dashboard.js +50 -6
  42. package/static/build/api/env.js +2 -2
  43. package/static/build/api/health.js +2 -2
  44. package/static/build/api/index.js +4 -0
  45. package/static/build/api/log.js +39 -19
  46. package/static/build/api/retention.js +63 -0
  47. package/static/build/api/script.js +23 -22
  48. package/static/build/api/subscription.js +16 -2
  49. package/static/build/api/system.js +31 -9
  50. package/static/build/api/user.js +75 -15
  51. package/static/build/app.js +63 -54
  52. package/static/build/bootstrap/database.js +51 -0
  53. package/static/build/config/const.js +2 -0
  54. package/static/build/config/grpcCerts.js +4 -4
  55. package/static/build/config/index.js +0 -4
  56. package/static/build/config/share.js +5 -4
  57. package/static/build/config/util.js +136 -41
  58. package/static/build/data/cron.js +1 -0
  59. package/static/build/data/notify.js +18 -1
  60. package/static/build/data/sock.js +1 -0
  61. package/static/build/loaders/app.js +8 -6
  62. package/static/build/loaders/db.js +5 -35
  63. package/static/build/loaders/deps.js +30 -22
  64. package/static/build/loaders/express.js +44 -32
  65. package/static/build/loaders/initData.js +10 -7
  66. package/static/build/loaders/initFile.js +1 -1
  67. package/static/build/loaders/initTask.js +3 -2
  68. package/static/build/loaders/server.js +1 -1
  69. package/static/build/loaders/sock.js +72 -6
  70. package/static/build/middlewares/monitoring.js +12 -33
  71. package/static/build/middlewares/protectedPathCase.js +17 -0
  72. package/static/build/protos/api.js +78 -2
  73. package/static/build/protos/cron.js +21 -4
  74. package/static/build/protos/health.js +1 -1
  75. package/static/build/schedule/addCron.js +76 -10
  76. package/static/build/schedule/api.js +5 -2
  77. package/static/build/schedule/client.js +38 -6
  78. package/static/build/schedule/delCron.js +11 -1
  79. package/static/build/schedule/health.js +72 -7
  80. package/static/build/services/config.js +5 -42
  81. package/static/build/services/cron.js +353 -164
  82. package/static/build/services/dependence.js +66 -18
  83. package/static/build/services/grpc.js +2 -2
  84. package/static/build/services/health.js +4 -7
  85. package/static/build/services/http.js +9 -3
  86. package/static/build/services/log.js +2 -3
  87. package/static/build/services/metrics.js +46 -14
  88. package/static/build/services/notify.js +73 -5
  89. package/static/build/services/retention.js +123 -0
  90. package/static/build/services/schedule.js +57 -33
  91. package/static/build/services/script.js +4 -5
  92. package/static/build/services/subscription.js +57 -34
  93. package/static/build/services/system.js +49 -11
  94. package/static/build/services/user.js +244 -31
  95. package/static/build/shared/auth.js +22 -3
  96. package/static/build/shared/authMutation.js +17 -0
  97. package/static/build/shared/childProcess.js +82 -0
  98. package/static/build/shared/clientIp.js +27 -0
  99. package/static/build/shared/errors.js +9 -0
  100. package/static/build/shared/fileAccess.js +60 -0
  101. package/static/build/shared/i18n.js +62 -4
  102. package/static/build/shared/logReader.js +85 -0
  103. package/static/build/shared/logStreamManager.js +80 -60
  104. package/static/build/shared/pLimit.js +3 -2
  105. package/static/build/shared/password.js +30 -0
  106. package/static/build/shared/retention.js +58 -0
  107. package/static/build/shared/runCron.js +28 -15
  108. package/static/build/shared/schedulerMutationLock.js +44 -0
  109. package/static/build/shared/schedulerReadiness.js +82 -0
  110. package/static/build/shared/schemaMigrations.js +58 -0
  111. package/static/build/shared/startupProcess.js +48 -0
  112. package/static/build/shared/store.js +7 -0
  113. package/static/build/shared/trustProxy.js +119 -0
  114. package/static/build/validation/schedule.js +12 -3
  115. package/static/dist/{1885.e1ea09f6.async.js → 1885.b8f427bf.async.js} +1 -1
  116. package/static/dist/2031.6af40025.async.js +1 -0
  117. package/static/dist/2693.51c2636b.async.js +1 -0
  118. package/static/dist/{2890.9e373f5b.async.js → 2890.add55e85.async.js} +1 -1
  119. package/static/dist/2901.2ca95295.async.js +1 -0
  120. package/static/dist/445.a65ff63b.async.js +1 -0
  121. package/static/dist/4736.1d2b5cb6.async.js +1 -0
  122. package/static/dist/{4859.6592cebb.async.js → 4859.97d6653c.async.js} +1 -1
  123. package/static/dist/{6013.4e38de36.async.js → 6013.db535339.async.js} +1 -1
  124. package/static/dist/6212.9e6d9913.async.js +1 -0
  125. package/static/dist/{6339.ab305e96.async.js → 6431.4603ad0e.async.js} +1 -1
  126. package/static/dist/{6872.42f939f1.async.js → 6872.a503ef55.async.js} +1 -1
  127. package/static/dist/7231.f7e5b668.async.js +1 -0
  128. package/static/dist/{7355.f9f263d8.async.js → 7355.fca746f5.async.js} +1 -1
  129. package/static/dist/{7508.7dcee91c.async.js → 7508.d90eac63.async.js} +1 -1
  130. package/static/dist/{7984.594296a5.async.js → 7984.eaac7402.async.js} +1 -1
  131. package/static/dist/8844.a0fef08e.async.js +1 -0
  132. package/static/dist/index.html +2 -2
  133. package/static/dist/layouts__index.633d3553.async.js +1 -0
  134. package/static/dist/preload_helper.cf7de3fa.js +1 -0
  135. package/static/dist/{src__pages__config__index.a22ff7dc.async.js → src__pages__config__index.9aba4054.async.js} +1 -1
  136. package/static/dist/src__pages__crontab__detail.86b2eebb.async.js +1 -0
  137. package/static/dist/src__pages__crontab__index.ae4e06f2.async.js +1 -0
  138. package/static/dist/{src__pages__crontab__logModal.0b8cce8c.async.js → src__pages__crontab__logModal.930535e2.async.js} +1 -1
  139. package/static/dist/src__pages__crontab__modal.a2c8fdcc.async.js +1 -0
  140. package/static/dist/src__pages__crontab__viewCreateModal.7b4f9cbe.async.js +1 -0
  141. package/static/dist/src__pages__crontab__viewManageModal.cd454ea0.async.js +1 -0
  142. package/static/dist/src__pages__dashboard__index.243c5a35.async.js +1 -0
  143. package/static/dist/src__pages__dashboard__taskResultModal.7795d6e1.async.js +1 -0
  144. package/static/dist/src__pages__dependence__index.874d501f.async.js +1 -0
  145. package/static/dist/src__pages__dependence__logModal.154efe7a.async.js +1 -0
  146. package/static/dist/src__pages__dependence__modal.a29c1a0f.async.js +1 -0
  147. package/static/dist/{src__pages__diff__index.013b7c75.async.js → src__pages__diff__index.1714b941.async.js} +1 -1
  148. package/static/dist/src__pages__env__editNameModal.c13d47d2.async.js +1 -0
  149. package/static/dist/src__pages__env__index.fd6fd2b0.async.js +1 -0
  150. package/static/dist/src__pages__env__modal.4d71adb3.async.js +1 -0
  151. package/static/dist/src__pages__error__index.aae50c94.async.js +1 -0
  152. package/static/dist/src__pages__initialization__index.82a2e967.async.js +1 -0
  153. package/static/dist/src__pages__log__index.71250e0d.async.js +1 -0
  154. package/static/dist/{src__pages__login__index.8c813eb1.async.js → src__pages__login__index.a0fd5ed8.async.js} +1 -1
  155. package/static/dist/src__pages__script__editModal.22acdf7c.async.js +1 -0
  156. package/static/dist/src__pages__script__editNameModal.1a521cc0.async.js +1 -0
  157. package/static/dist/src__pages__script__index.a18b2692.async.js +1 -0
  158. package/static/dist/src__pages__script__renameModal.0ab029e7.async.js +1 -0
  159. package/static/dist/src__pages__script__saveModal.8965b74c.async.js +1 -0
  160. package/static/dist/src__pages__script__setting.35ad4f02.async.js +1 -0
  161. package/static/dist/src__pages__setting__appModal.7eaeb9d3.async.js +1 -0
  162. package/static/dist/src__pages__setting__checkUpdate.d175b154.async.js +1 -0
  163. package/static/dist/src__pages__setting__clientIp.3a8711ed.async.js +1 -0
  164. package/static/dist/src__pages__setting__dependence.9c0f749b.async.js +1 -0
  165. package/static/dist/src__pages__setting__index.cb397741.async.js +1 -0
  166. package/static/dist/src__pages__setting__loginLog.e0a1f54d.async.js +1 -0
  167. package/static/dist/src__pages__setting__notification.2ffe4e5a.async.js +1 -0
  168. package/static/dist/src__pages__setting__other.3d0b8492.async.js +1 -0
  169. package/static/dist/{src__pages__setting__progress.8823ac90.async.js → src__pages__setting__progress.2ccae3d7.async.js} +1 -1
  170. package/static/dist/src__pages__setting__security.e2d71ebb.async.js +1 -0
  171. package/static/dist/src__pages__setting__systemLog.b3046955.async.js +1 -0
  172. package/static/dist/src__pages__subscription__index.43086a06.async.js +1 -0
  173. package/static/dist/src__pages__subscription__logModal.cdba5139.async.js +1 -0
  174. package/static/dist/src__pages__subscription__modal.38991e1e.async.js +1 -0
  175. package/static/dist/{umi.ca04a019.js → umi.fc019050.js} +1 -1
  176. package/test/back/auth-security.test.cjs +74 -0
  177. package/test/back/build-provenance.test.cjs +150 -0
  178. package/test/back/cron-log-name.test.cjs +110 -0
  179. package/test/back/cron-validation.test.cjs +45 -0
  180. package/test/back/dashboard-failures.test.cjs +173 -0
  181. package/test/back/database-bootstrap.test.cjs +193 -0
  182. package/test/back/dependence-cache-status.test.cjs +125 -0
  183. package/test/back/deprecated-file-routes.test.cjs +82 -0
  184. package/test/back/ecosystem.test.cjs +28 -0
  185. package/test/back/env-name-parsing.test.cjs +96 -0
  186. package/test/back/execution-lifecycle.test.cjs +236 -0
  187. package/test/back/file-access-security.test.cjs +47 -0
  188. package/test/back/fileTreeListing.test.cjs +57 -0
  189. package/test/back/grpc-cron-response.test.cjs +60 -0
  190. package/test/back/http-exclusive-listen.test.cjs +31 -0
  191. package/test/back/http-security.test.cjs +213 -0
  192. package/test/back/listen-security.test.cjs +67 -0
  193. package/test/back/log-path-security.test.cjs +158 -0
  194. package/test/back/logReader.test.cjs +72 -0
  195. package/test/back/manual-execution.test.cjs +85 -0
  196. package/test/back/manual-stop-claim.test.cjs +220 -0
  197. package/test/back/metrics.test.cjs +34 -0
  198. package/test/back/monitoring.test.cjs +73 -0
  199. package/test/back/node-path-cache.test.cjs +173 -0
  200. package/test/back/node-path-lock.test.cjs +178 -0
  201. package/test/back/npm-publication.test.cjs +70 -0
  202. package/test/back/primary-apm.test.cjs +24 -0
  203. package/test/back/process-exit-state.test.cjs +81 -0
  204. package/test/back/process-stop-signal.test.cjs +77 -0
  205. package/test/back/protected-path-case.test.cjs +58 -0
  206. package/test/back/qlServiceLogCommand.test.cjs +128 -0
  207. package/test/back/retention.test.cjs +131 -0
  208. package/test/back/role-loading.test.cjs +118 -0
  209. package/test/back/schedule-health.test.cjs +86 -0
  210. package/test/back/scheduler-file-lock.test.cjs +51 -0
  211. package/test/back/scheduler-mutation.test.cjs +312 -0
  212. package/test/back/scheduler-readiness.test.cjs +85 -0
  213. package/test/back/scheduler-reconciliation.test.cjs +152 -0
  214. package/test/back/scheduler-rpc-timeout.test.cjs +49 -0
  215. package/test/back/schema-migrations.test.cjs +127 -0
  216. package/test/back/shell-api-parsing.test.cjs +184 -0
  217. package/test/back/sock-polling.test.cjs +297 -0
  218. package/test/back/sock-security.test.cjs +72 -0
  219. package/test/back/start-env-preservation.test.cjs +53 -0
  220. package/test/back/stop-failure-feedback.test.cjs +158 -0
  221. package/test/back/stop-race.test.cjs +167 -0
  222. package/test/back/subscription-cleanup.test.cjs +53 -0
  223. package/test/back/subscription-stop-state.test.cjs +66 -0
  224. package/test/back/system-dependence-cache.test.cjs +126 -0
  225. package/test/back/task-time.test.cjs +116 -0
  226. package/test/back/user-api.test.cjs +99 -0
  227. package/test/back/user-security.test.cjs +248 -0
  228. package/test/back/worker-apm.test.cjs +84 -0
  229. package/test/back/wpush-grpc.test.cjs +115 -0
  230. package/test/front/cron-log-pagination.test.cjs +214 -0
  231. package/test/front/http-auth.test.cjs +152 -0
  232. package/test/front/http-error.test.cjs +29 -0
  233. package/test/helpers/load-security-module.cjs +42 -0
  234. package/version.yaml +19 -34
  235. package/CLAUDE.md +0 -43
  236. package/static/dist/1147.c420132e.async.js +0 -1
  237. package/static/dist/134.54df9e38.async.js +0 -1
  238. package/static/dist/2208.f7ba3dfa.async.js +0 -1
  239. package/static/dist/2286.164bb089.async.js +0 -1
  240. package/static/dist/3191.63263871.async.js +0 -1
  241. package/static/dist/4902.555f92ab.async.js +0 -1
  242. package/static/dist/5520.ff2cfd6b.async.js +0 -1
  243. package/static/dist/6431.c50479be.async.js +0 -1
  244. package/static/dist/8826.2447a104.async.js +0 -1
  245. package/static/dist/layouts__index.a7a2bfe0.async.js +0 -1
  246. package/static/dist/preload_helper.0431c0f3.js +0 -1
  247. package/static/dist/src__pages__crontab__detail.b9c36808.async.js +0 -1
  248. package/static/dist/src__pages__crontab__index.fed99fd0.async.js +0 -1
  249. package/static/dist/src__pages__crontab__modal.f7041c7c.async.js +0 -1
  250. package/static/dist/src__pages__crontab__viewCreateModal.4d589f66.async.js +0 -1
  251. package/static/dist/src__pages__crontab__viewManageModal.0e317746.async.js +0 -1
  252. package/static/dist/src__pages__dashboard__index.b30f2f47.async.js +0 -1
  253. package/static/dist/src__pages__dependence__index.3d87ceac.async.js +0 -1
  254. package/static/dist/src__pages__dependence__logModal.0681830b.async.js +0 -1
  255. package/static/dist/src__pages__dependence__modal.11124896.async.js +0 -1
  256. package/static/dist/src__pages__env__editNameModal.5d264b25.async.js +0 -1
  257. package/static/dist/src__pages__env__index.baa27d4e.async.js +0 -1
  258. package/static/dist/src__pages__env__modal.7f2ef1bc.async.js +0 -1
  259. package/static/dist/src__pages__error__index.f156b45e.async.js +0 -1
  260. package/static/dist/src__pages__initialization__index.e96d4ba8.async.js +0 -1
  261. package/static/dist/src__pages__log__index.e0978bae.async.js +0 -1
  262. package/static/dist/src__pages__script__editModal.cbf4ec0e.async.js +0 -1
  263. package/static/dist/src__pages__script__editNameModal.3e7e100d.async.js +0 -1
  264. package/static/dist/src__pages__script__index.2765d1b8.async.js +0 -1
  265. package/static/dist/src__pages__script__renameModal.5e987ef5.async.js +0 -1
  266. package/static/dist/src__pages__script__saveModal.3f9d23d6.async.js +0 -1
  267. package/static/dist/src__pages__script__setting.a535793a.async.js +0 -1
  268. package/static/dist/src__pages__setting__appModal.251cd14f.async.js +0 -1
  269. package/static/dist/src__pages__setting__checkUpdate.46efe057.async.js +0 -1
  270. package/static/dist/src__pages__setting__dependence.8a7a9529.async.js +0 -1
  271. package/static/dist/src__pages__setting__index.cc85fdfb.async.js +0 -1
  272. package/static/dist/src__pages__setting__loginLog.cea6056c.async.js +0 -1
  273. package/static/dist/src__pages__setting__notification.390fc905.async.js +0 -1
  274. package/static/dist/src__pages__setting__other.b22d2165.async.js +0 -1
  275. package/static/dist/src__pages__setting__security.598720a8.async.js +0 -1
  276. package/static/dist/src__pages__setting__systemLog.67406721.async.js +0 -1
  277. package/static/dist/src__pages__subscription__index.d0ab2abc.async.js +0 -1
  278. package/static/dist/src__pages__subscription__logModal.3864b37f.async.js +0 -1
  279. package/static/dist/src__pages__subscription__modal.3562c670.async.js +0 -1
@@ -33,6 +33,7 @@ const toad_scheduler_1 = require("toad-scheduler");
33
33
  const dayjs_1 = __importDefault(require("dayjs"));
34
34
  const pLimit_1 = __importDefault(require("../shared/pLimit"));
35
35
  const cross_spawn_1 = require("cross-spawn");
36
+ const childProcess_1 = require("../shared/childProcess");
36
37
  let ScheduleService = class ScheduleService {
37
38
  constructor(logger) {
38
39
  this.logger = logger;
@@ -46,44 +47,67 @@ let ScheduleService = class ScheduleService {
46
47
  }
47
48
  async runTask(command, callbacks = {}, params, completionTime = 'end') {
48
49
  const { runOrigin } = params, others = __rest(params, ["runOrigin"]);
49
- return pLimit_1.default[this.taskLimitMap[runOrigin]](others, () => {
50
- return new Promise(async (resolve, reject) => {
51
- var _a, _b, _c;
52
- this.logger.info(`[panel][开始执行任务] 参数: ${JSON.stringify(Object.assign(Object.assign({}, others), { command }))}`);
53
- try {
54
- const startTime = (0, dayjs_1.default)();
55
- await ((_a = callbacks.onBefore) === null || _a === void 0 ? void 0 : _a.call(callbacks, startTime));
56
- const cp = (0, cross_spawn_1.spawn)(command, { shell: '/bin/bash' });
57
- (_b = callbacks.onStart) === null || _b === void 0 ? void 0 : _b.call(callbacks, cp, startTime);
58
- completionTime === 'start' && resolve(cp.pid);
59
- cp.stdout.on('data', async (data) => {
60
- var _a;
61
- await ((_a = callbacks.onLog) === null || _a === void 0 ? void 0 : _a.call(callbacks, data.toString()));
62
- });
63
- cp.stderr.on('data', async (data) => {
64
- var _a;
65
- this.logger.info('[panel][执行任务失败] 命令: %s, 错误信息: %j', command, data.toString());
66
- await ((_a = callbacks.onError) === null || _a === void 0 ? void 0 : _a.call(callbacks, data.toString()));
67
- });
68
- cp.on('error', async (err) => {
69
- var _a;
70
- this.logger.error('[panel][创建任务失败] 命令: %s, 错误信息: %j', command, err);
71
- await ((_a = callbacks.onError) === null || _a === void 0 ? void 0 : _a.call(callbacks, JSON.stringify(err)));
72
- });
73
- cp.on('exit', async (code) => {
50
+ let resolveStart;
51
+ let rejectStart;
52
+ const startResult = new Promise((resolve, reject) => {
53
+ resolveStart = resolve;
54
+ rejectStart = reject;
55
+ });
56
+ // Most scheduled callers only observe completion (or intentionally detach).
57
+ void startResult.catch(() => { });
58
+ const completion = pLimit_1.default[this.taskLimitMap[runOrigin]](others, async () => {
59
+ var _a, _b, _c, _d;
60
+ const startTime = (0, dayjs_1.default)();
61
+ let cp;
62
+ let result = { code: null, signal: null };
63
+ try {
64
+ this.logger.info('[panel][开始执行任务] 任务ID: %s', others.id);
65
+ await ((_a = callbacks.onBefore) === null || _a === void 0 ? void 0 : _a.call(callbacks, startTime));
66
+ cp = (0, cross_spawn_1.spawn)(command, { shell: '/bin/bash' });
67
+ const child = cp;
68
+ const observed = (0, childProcess_1.observeChildProcess)(child, {
69
+ onStart: async () => {
74
70
  var _a;
75
- this.logger.info('[panel][执行任务结束] 参数: %s, 退出码: %j', JSON.stringify(Object.assign(Object.assign({}, others), { command })), code);
76
- const endTime = (0, dayjs_1.default)();
77
- await ((_a = callbacks.onEnd) === null || _a === void 0 ? void 0 : _a.call(callbacks, cp, endTime, endTime.diff(startTime, 'seconds')));
78
- resolve(Object.assign(Object.assign({}, others), { pid: cp.pid, code }));
79
- });
71
+ await ((_a = callbacks.onStart) === null || _a === void 0 ? void 0 : _a.call(callbacks, child, startTime));
72
+ },
73
+ onStdout: callbacks.onLog,
74
+ onStderr: callbacks.onError,
75
+ });
76
+ observed.started.then(resolveStart, rejectStart);
77
+ result = await observed.completed;
78
+ }
79
+ catch (error) {
80
+ result.error = (0, childProcess_1.asError)(error);
81
+ rejectStart(result.error);
82
+ }
83
+ if (result.error) {
84
+ this.logger.error('[panel][执行任务失败] 任务ID: %s, 错误: %s', others.id, result.error.message);
85
+ try {
86
+ await ((_b = callbacks.onError) === null || _b === void 0 ? void 0 : _b.call(callbacks, result.error.message));
80
87
  }
81
88
  catch (error) {
82
- this.logger.error('[panel][执行任务失败] 命令: %s, 错误信息: %j', command, error);
83
- await ((_c = callbacks.onError) === null || _c === void 0 ? void 0 : _c.call(callbacks, JSON.stringify(error)));
89
+ this.logger.error('[panel][任务错误回调失败] %s', (0, childProcess_1.asError)(error).message);
84
90
  }
85
- });
91
+ }
92
+ // Cleanup also runs after setup/spawn failure, and only after both pipes drain.
93
+ const endTime = (0, dayjs_1.default)();
94
+ try {
95
+ await ((_c = callbacks.onEnd) === null || _c === void 0 ? void 0 : _c.call(callbacks, cp, endTime, endTime.diff(startTime, 'seconds')));
96
+ }
97
+ catch (error) {
98
+ (_d = result.error) !== null && _d !== void 0 ? _d : (result.error = (0, childProcess_1.asError)(error));
99
+ this.logger.error('[panel][任务结束回调失败] %s', (0, childProcess_1.asError)(error).message);
100
+ }
101
+ this.logger.info('[panel][执行任务结束] 任务ID: %s, 退出码: %j', others.id, result.code);
102
+ return Object.assign(Object.assign(Object.assign({}, others), { pid: cp === null || cp === void 0 ? void 0 : cp.pid }), result);
103
+ }).catch((error) => {
104
+ // Queue/setup failures must not become unhandled rejections in detached callers.
105
+ rejectStart((0, childProcess_1.asError)(error));
106
+ this.logger.error('[panel][任务队列失败] %s', (0, childProcess_1.asError)(error).message);
107
+ return Object.assign(Object.assign({}, others), { code: null, signal: null, error: (0, childProcess_1.asError)(error) });
86
108
  });
109
+ // Returning a PID must not release the execution slot while the process runs.
110
+ return completionTime === 'start' ? startResult : completion;
87
111
  }
88
112
  async createCronTask({ id = 0, command, name, schedule = '', runOrigin }, callbacks, runImmediately = false) {
89
113
  const _id = this.formatId(id);
@@ -15,6 +15,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
15
15
  return (mod && mod.__esModule) ? mod : { "default": mod };
16
16
  };
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
+ const fileAccess_1 = require("../shared/fileAccess");
18
19
  const typedi_1 = require("typedi");
19
20
  const winston_1 = __importDefault(require("winston"));
20
21
  const path_1 = __importDefault(require("path"));
@@ -63,15 +64,13 @@ let ScriptService = class ScriptService {
63
64
  pLimit_1.default.removeQueuedCron(relativePath.replace(/ /g, '-'));
64
65
  pid = (await (0, util_1.getPid)(`${const_1.TASK_COMMAND} ${relativePath} now`));
65
66
  }
66
- try {
67
- await (0, util_1.killTask)(pid);
67
+ if (pid) {
68
+ await (0, util_1.killTask)(pid, true);
68
69
  }
69
- catch (error) { }
70
70
  return { code: 200 };
71
71
  }
72
72
  checkFilePath(filePath, fileName) {
73
- const finalPath = path_1.default.resolve(config_1.default.scriptPath, filePath, fileName);
74
- return finalPath.startsWith(config_1.default.scriptPath) ? finalPath : '';
73
+ return (0, fileAccess_1.resolveFileAccess)(config_1.default.scriptPath, [filePath || '', fileName], config_1.default.blackFileList);
75
74
  }
76
75
  async getFile(filePath, fileName) {
77
76
  const finalPath = this.checkFilePath(filePath, fileName);
@@ -55,6 +55,7 @@ const subscription_2 = require("../config/subscription");
55
55
  const cron_1 = require("../data/cron");
56
56
  const cron_2 = __importDefault(require("./cron"));
57
57
  const logStreamManager_1 = require("../shared/logStreamManager");
58
+ const logReader_1 = require("../shared/logReader");
58
59
  let SubscriptionService = class SubscriptionService {
59
60
  constructor(logger, scheduleService, sockService, sshKeyService, crontabService) {
60
61
  this.logger = logger;
@@ -126,12 +127,12 @@ let SubscriptionService = class SubscriptionService {
126
127
  status: subscription_1.SubscriptionStatus.running,
127
128
  log_path: logPath,
128
129
  }, { where: { id: doc.id } });
129
- const absolutePath = await (0, util_1.handleLogPath)(logPath, `## 开始执行... ${startTime.format('YYYY-MM-DD HH:mm:ss')}\n`);
130
+ const absolutePath = await (0, util_1.handleLogPath)(logPath, (0, i18n_1.tf)('## 开始执行... %s\n', startTime.format('YYYY-MM-DD HH:mm:ss')));
130
131
  // 执行sub_before
131
132
  let beforeStr = '';
132
133
  try {
133
134
  if (doc.sub_before) {
134
- await logStreamManager_1.logStreamManager.write(absolutePath, `\n## 执行before命令...\n\n`);
135
+ await logStreamManager_1.logStreamManager.write(absolutePath, `\n## ${(0, i18n_1.t)('执行before命令...')}\n\n`);
135
136
  beforeStr = await (0, util_1.promiseExec)(doc.sub_before);
136
137
  }
137
138
  }
@@ -149,32 +150,43 @@ let SubscriptionService = class SubscriptionService {
149
150
  }, { where: { id: doc.id } });
150
151
  },
151
152
  onEnd: async (cp, endTime, diff) => {
152
- const sub = await this.getDb({ id: doc.id });
153
- const absolutePath = await (0, util_1.handleLogPath)(sub.log_path);
154
- // 执行 sub_after
155
- let afterStr = '';
153
+ let absolutePath;
156
154
  try {
157
- if (sub.sub_after) {
158
- await logStreamManager_1.logStreamManager.write(absolutePath, `\n\n## 执行after命令...\n\n`);
159
- afterStr = await (0, util_1.promiseExec)(sub.sub_after);
155
+ const sub = await this.getDb({ id: doc.id });
156
+ absolutePath = await (0, util_1.handleLogPath)(sub.log_path);
157
+ // 执行 sub_after
158
+ let afterStr = '';
159
+ try {
160
+ if (sub.sub_after) {
161
+ await logStreamManager_1.logStreamManager.write(absolutePath, `\n\n## ${(0, i18n_1.t)('执行after命令...')}\n\n`);
162
+ afterStr = await (0, util_1.promiseExec)(sub.sub_after);
163
+ }
160
164
  }
165
+ catch (error) {
166
+ afterStr =
167
+ (error.stderr && error.stderr.toString()) || JSON.stringify(error);
168
+ }
169
+ if (afterStr) {
170
+ await logStreamManager_1.logStreamManager.write(absolutePath, `${afterStr}\n`);
171
+ }
172
+ await logStreamManager_1.logStreamManager.write(absolutePath, '\n' +
173
+ (0, i18n_1.tf)('## 执行结束... %s 耗时 %s 秒', endTime.format('YYYY-MM-DD HH:mm:ss'), String(diff)) +
174
+ const_1.LOG_END_SYMBOL);
161
175
  }
162
- catch (error) {
163
- afterStr =
164
- (error.stderr && error.stderr.toString()) || JSON.stringify(error);
165
- }
166
- if (afterStr) {
167
- await logStreamManager_1.logStreamManager.write(absolutePath, `${afterStr}\n`);
176
+ finally {
177
+ try {
178
+ if (absolutePath)
179
+ await logStreamManager_1.logStreamManager.closeStream(absolutePath);
180
+ }
181
+ finally {
182
+ await subscription_1.SubscriptionModel.update({ status: subscription_1.SubscriptionStatus.idle, pid: null }, { where: { id: doc.id } });
183
+ this.sockService.sendMessage({
184
+ type: 'runSubscriptionEnd',
185
+ message: (0, i18n_1.t)('订阅执行完成'),
186
+ references: [doc.id],
187
+ });
188
+ }
168
189
  }
169
- await logStreamManager_1.logStreamManager.write(absolutePath, `\n## 执行结束... ${endTime.format('YYYY-MM-DD HH:mm:ss')} 耗时 ${diff} 秒${const_1.LOG_END_SYMBOL}`);
170
- // Close the stream after task completion
171
- await logStreamManager_1.logStreamManager.closeStream(absolutePath);
172
- await subscription_1.SubscriptionModel.update({ status: subscription_1.SubscriptionStatus.idle, pid: undefined }, { where: { id: sub.id } });
173
- this.sockService.sendMessage({
174
- type: 'runSubscriptionEnd',
175
- message: (0, i18n_1.t)('订阅执行完成'),
176
- references: [doc.id],
177
- });
178
190
  },
179
191
  onError: async (message) => {
180
192
  const sub = await this.getDb({ id: doc.id });
@@ -256,18 +268,23 @@ let SubscriptionService = class SubscriptionService {
256
268
  });
257
269
  }
258
270
  async stop(ids) {
271
+ var _a;
259
272
  const docs = await subscription_1.SubscriptionModel.findAll({ where: { id: ids } });
273
+ let failure;
260
274
  for (const doc of docs) {
261
- if (doc.pid) {
262
- try {
263
- await (0, util_1.killTask)(doc.pid);
264
- }
265
- catch (error) {
266
- this.logger.error(error);
275
+ try {
276
+ if (doc.pid) {
277
+ await (0, util_1.killTask)(doc.pid, true);
267
278
  }
279
+ await subscription_1.SubscriptionModel.update({ status: subscription_1.SubscriptionStatus.idle, pid: null }, { where: { id: doc.id, pid: (_a = doc.pid) !== null && _a !== void 0 ? _a : null } });
280
+ }
281
+ catch (error) {
282
+ this.logger.error(error);
283
+ failure !== null && failure !== void 0 ? failure : (failure = error);
268
284
  }
269
285
  }
270
- await subscription_1.SubscriptionModel.update({ status: subscription_1.SubscriptionStatus.idle, pid: undefined }, { where: { id: ids } });
286
+ if (failure)
287
+ throw failure;
271
288
  }
272
289
  async runSingle(subscriptionId) {
273
290
  const subscription = await this.getDb({ id: subscriptionId });
@@ -299,13 +316,19 @@ let SubscriptionService = class SubscriptionService {
299
316
  await this.handleTask(doc.get({ plain: true }));
300
317
  }
301
318
  }
302
- async log(id) {
319
+ async log(id, options = {}) {
303
320
  const doc = await this.getDb({ id });
304
321
  if (!doc || !doc.log_path) {
305
- return '';
322
+ return {
323
+ content: '',
324
+ offset: 0,
325
+ nextOffset: 0,
326
+ total: 0,
327
+ truncated: false,
328
+ };
306
329
  }
307
330
  const absolutePath = await (0, util_1.handleLogPath)(doc.log_path);
308
- return await (0, util_1.getFileContentByName)(absolutePath);
331
+ return await (0, logReader_1.readLogChunk)(absolutePath, options);
309
332
  }
310
333
  async logs(id) {
311
334
  const doc = await this.getDb({ id });
@@ -29,7 +29,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
29
29
  const cross_spawn_1 = require("cross-spawn");
30
30
  const fs_1 = __importDefault(require("fs"));
31
31
  const undici_1 = require("undici");
32
- const sum_1 = __importDefault(require("lodash/sum"));
33
32
  const path_1 = __importDefault(require("path"));
34
33
  const typedi_1 = require("typedi");
35
34
  const winston_1 = __importDefault(require("winston"));
@@ -72,7 +71,7 @@ let SystemService = class SystemService {
72
71
  }
73
72
  async updateNotificationMode(notificationInfo) {
74
73
  const code = Math.random().toString().slice(-6);
75
- const isSuccess = await this.notificationService.testNotify(notificationInfo, '青龙', `【蛟龙】测试通知 https://t.me/jiao_long`);
74
+ const isSuccess = await this.notificationService.testNotify(notificationInfo, (0, i18n_1.t)('青龙'), (0, i18n_1.t)('【蛟龙】测试通知 https://t.me/jiao_long'));
76
75
  if (isSuccess) {
77
76
  const result = await this.updateAuthDb({
78
77
  type: system_1.AuthDataType.notification,
@@ -90,7 +89,7 @@ let SystemService = class SystemService {
90
89
  const result = await this.updateAuthDb(Object.assign(Object.assign({}, oDoc), { info: Object.assign(Object.assign({}, oDoc.info), info) }));
91
90
  const cron = {
92
91
  id: result.id,
93
- name: '删除日志',
92
+ name: (0, i18n_1.t)('删除日志'),
94
93
  command: `ql rmlog ${info.logRemoveFrequency}`,
95
94
  runOrigin: 'system',
96
95
  };
@@ -149,6 +148,7 @@ let SystemService = class SystemService {
149
148
  this.sockService.sendMessage({
150
149
  type: 'updateNodeMirror',
151
150
  message: 'update node mirror end',
151
+ status: 'completed',
152
152
  });
153
153
  },
154
154
  onError: async (message) => {
@@ -189,6 +189,7 @@ let SystemService = class SystemService {
189
189
  this.sockService.sendMessage({
190
190
  type: 'updateLinuxMirror',
191
191
  message: 'update linux mirror end',
192
+ status: 'completed',
192
193
  });
193
194
  onEnd === null || onEnd === void 0 ? void 0 : onEnd();
194
195
  if (!hasError) {
@@ -277,6 +278,14 @@ let SystemService = class SystemService {
277
278
  this.sockService.sendMessage({
278
279
  type: 'updateSystemVersion',
279
280
  message: JSON.stringify(err),
281
+ status: 'failed',
282
+ });
283
+ });
284
+ cp.on('exit', (code) => {
285
+ this.sockService.sendMessage({
286
+ type: 'updateSystemVersion',
287
+ message: '',
288
+ status: code === 0 ? 'success' : 'failed',
280
289
  });
281
290
  });
282
291
  return { code: 200 };
@@ -376,8 +385,24 @@ let SystemService = class SystemService {
376
385
  .reverse()
377
386
  .filter((x) => x.title.endsWith('.log'))
378
387
  .filter((x) => x.createTime >= startTime && x.createTime <= endTime);
388
+ const limit = Math.min(Math.max(Number(query.limit) || 1024 * 1024, 1), 1024 * 1024);
389
+ const total = logs.reduce((size, log) => size + (log.size || 0), 0);
390
+ let remaining = limit;
391
+ const selected = [];
392
+ for (let index = logs.length - 1; index >= 0 && remaining > 0; index--) {
393
+ const log = logs[index];
394
+ const size = log.size || 0;
395
+ const length = Math.min(size, remaining);
396
+ if (length > 0) {
397
+ selected.unshift(Object.assign(Object.assign({}, log), { start: size - length, length }));
398
+ remaining -= length;
399
+ }
400
+ }
401
+ const contentLength = selected.reduce((size, log) => size + log.length, 0);
379
402
  res.set({
380
- 'Content-Length': (0, sum_1.default)(logs.map((x) => x.size)),
403
+ 'Content-Length': contentLength,
404
+ 'X-QL-Log-Total': total,
405
+ 'X-QL-Log-Truncated': total > contentLength ? 'true' : 'false',
381
406
  });
382
407
  (function sendFiles(res, fileNames) {
383
408
  if (fileNames.length === 0) {
@@ -386,13 +411,16 @@ let SystemService = class SystemService {
386
411
  }
387
412
  const currentLog = fileNames.shift();
388
413
  if (currentLog) {
389
- const currentFileStream = fs_1.default.createReadStream(path_1.default.join(config_1.default.systemLogPath, currentLog.title));
414
+ const currentFileStream = fs_1.default.createReadStream(path_1.default.join(config_1.default.systemLogPath, currentLog.title), {
415
+ start: currentLog.start,
416
+ end: currentLog.start + currentLog.length - 1,
417
+ });
390
418
  currentFileStream.on('end', () => {
391
419
  sendFiles(res, fileNames);
392
420
  });
393
421
  currentFileStream.pipe(res, { end: false });
394
422
  }
395
- })(res, logs);
423
+ })(res, selected);
396
424
  }
397
425
  async deleteSystemLog() {
398
426
  const result = await (0, util_1.readDirs)(config_1.default.systemLogPath, config_1.default.systemLogPath);
@@ -429,6 +457,13 @@ let SystemService = class SystemService {
429
457
  (0, i18n_1.setLang)(lang);
430
458
  return { code: 200, data: { lang } };
431
459
  }
460
+ async updatePanelTitle(info) {
461
+ var _a;
462
+ const oDoc = await this.getSystemConfig();
463
+ const panelTitle = ((_a = info.panelTitle) === null || _a === void 0 ? void 0 : _a.trim()) || '';
464
+ await this.updateAuthDb(Object.assign(Object.assign({}, oDoc), { info: Object.assign(Object.assign({}, oDoc.info), { panelTitle }) }));
465
+ return { code: 200, data: { panelTitle } };
466
+ }
432
467
  async updateGlobalSshKey(info) {
433
468
  const oDoc = await this.getSystemConfig();
434
469
  const result = await this.updateAuthDb(Object.assign(Object.assign({}, oDoc), { info: Object.assign(Object.assign({}, oDoc.info), info) }));
@@ -448,11 +483,14 @@ let SystemService = class SystemService {
448
483
  if (!type || !['node', 'python3'].includes(type)) {
449
484
  return { code: 400, message: (0, i18n_1.t)('参数错误') };
450
485
  }
451
- try {
452
- const finalPath = path_1.default.join(config_1.default.dependenceCachePath, type);
453
- await fs_1.default.promises.rm(finalPath, { recursive: true });
454
- }
455
- catch (error) { }
486
+ const finalPath = path_1.default.join(config_1.default.dependenceCachePath, type);
487
+ await fs_1.default.promises.rm(finalPath, { recursive: true, force: true });
488
+ await dependence_1.DependenceModel.update({ status: dependence_1.DependenceStatus.installFailed }, {
489
+ where: {
490
+ type: type === 'node' ? dependence_1.DependenceTypes.nodejs : dependence_1.DependenceTypes.python3,
491
+ status: dependence_1.DependenceStatus.installed,
492
+ },
493
+ });
456
494
  return { code: 200 };
457
495
  }
458
496
  };