@whyour/qinglong 2.21.0-8 → 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 (265) 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 +6 -1
  7. package/back/protos/cron.proto +4 -1
  8. package/docker/Dockerfile +31 -12
  9. package/docker/Dockerfile.310 +31 -12
  10. package/docker/Dockerfile.debian +22 -14
  11. package/docker/Dockerfile.debian310 +24 -14
  12. package/docker/build-manifest.cjs +28 -0
  13. package/docker/verify-build.cjs +49 -0
  14. package/docs/releases/2.22.0-validation.md +49 -0
  15. package/docs/releases/2.22.0.md +54 -0
  16. package/ecosystem.config.js +10 -1
  17. package/package.json +11 -6
  18. package/sample/config.sample.sh +10 -0
  19. package/sample/notify.js +54 -0
  20. package/sample/notify.py +37 -0
  21. package/scripts/benchmark-execution.cjs +96 -0
  22. package/scripts/write-build-info.cjs +27 -0
  23. package/shell/api.sh +34 -13
  24. package/shell/check.sh +59 -19
  25. package/shell/lang/en.sh +6 -0
  26. package/shell/lang/zh.sh +6 -0
  27. package/shell/node_path_cache.sh +128 -0
  28. package/shell/otask.sh +7 -1
  29. package/shell/preload/sitecustomize.js +5 -1
  30. package/shell/share.sh +25 -8
  31. package/shell/start.sh +6 -3
  32. package/shell/task.sh +13 -3
  33. package/shell/update.sh +65 -4
  34. package/static/build/api/clientIp.js +42 -0
  35. package/static/build/api/config.js +8 -16
  36. package/static/build/api/cron.js +38 -2
  37. package/static/build/api/dashboard.js +37 -0
  38. package/static/build/api/health.js +2 -2
  39. package/static/build/api/index.js +4 -0
  40. package/static/build/api/log.js +30 -19
  41. package/static/build/api/retention.js +63 -0
  42. package/static/build/api/script.js +23 -22
  43. package/static/build/api/subscription.js +16 -2
  44. package/static/build/api/system.js +25 -2
  45. package/static/build/api/user.js +75 -15
  46. package/static/build/app.js +54 -45
  47. package/static/build/bootstrap/database.js +51 -0
  48. package/static/build/config/const.js +1 -0
  49. package/static/build/config/share.js +5 -4
  50. package/static/build/config/util.js +133 -38
  51. package/static/build/data/cron.js +1 -0
  52. package/static/build/data/notify.js +11 -1
  53. package/static/build/loaders/app.js +2 -0
  54. package/static/build/loaders/db.js +3 -33
  55. package/static/build/loaders/deps.js +29 -0
  56. package/static/build/loaders/express.js +30 -21
  57. package/static/build/loaders/initData.js +10 -7
  58. package/static/build/loaders/sock.js +72 -6
  59. package/static/build/middlewares/monitoring.js +12 -33
  60. package/static/build/middlewares/protectedPathCase.js +17 -0
  61. package/static/build/protos/api.js +56 -2
  62. package/static/build/protos/cron.js +21 -4
  63. package/static/build/protos/health.js +1 -1
  64. package/static/build/schedule/addCron.js +9 -0
  65. package/static/build/schedule/api.js +5 -2
  66. package/static/build/schedule/client.js +38 -6
  67. package/static/build/schedule/health.js +72 -7
  68. package/static/build/services/config.js +5 -42
  69. package/static/build/services/cron.js +338 -199
  70. package/static/build/services/dependence.js +47 -0
  71. package/static/build/services/grpc.js +1 -1
  72. package/static/build/services/health.js +4 -7
  73. package/static/build/services/http.js +8 -2
  74. package/static/build/services/log.js +2 -3
  75. package/static/build/services/metrics.js +46 -14
  76. package/static/build/services/notify.js +26 -0
  77. package/static/build/services/retention.js +123 -0
  78. package/static/build/services/schedule.js +57 -33
  79. package/static/build/services/script.js +4 -5
  80. package/static/build/services/subscription.js +55 -34
  81. package/static/build/services/system.js +37 -9
  82. package/static/build/services/user.js +213 -25
  83. package/static/build/shared/auth.js +18 -5
  84. package/static/build/shared/authMutation.js +17 -0
  85. package/static/build/shared/childProcess.js +82 -0
  86. package/static/build/shared/clientIp.js +27 -0
  87. package/static/build/shared/errors.js +9 -0
  88. package/static/build/shared/fileAccess.js +60 -0
  89. package/static/build/shared/i18n.js +12 -5
  90. package/static/build/shared/logReader.js +85 -0
  91. package/static/build/shared/logStreamManager.js +80 -60
  92. package/static/build/shared/password.js +30 -0
  93. package/static/build/shared/retention.js +58 -0
  94. package/static/build/shared/runCron.js +28 -15
  95. package/static/build/shared/schedulerMutationLock.js +44 -0
  96. package/static/build/shared/schedulerReadiness.js +82 -0
  97. package/static/build/shared/schemaMigrations.js +58 -0
  98. package/static/build/shared/startupProcess.js +48 -0
  99. package/static/build/shared/store.js +7 -0
  100. package/static/build/shared/trustProxy.js +119 -0
  101. package/static/build/validation/schedule.js +3 -3
  102. package/static/dist/{1885.e1ea09f6.async.js → 1885.b8f427bf.async.js} +1 -1
  103. package/static/dist/2031.6af40025.async.js +1 -0
  104. package/static/dist/2693.51c2636b.async.js +1 -0
  105. package/static/dist/{2890.9e373f5b.async.js → 2890.add55e85.async.js} +1 -1
  106. package/static/dist/2901.2ca95295.async.js +1 -0
  107. package/static/dist/445.a65ff63b.async.js +1 -0
  108. package/static/dist/4736.1d2b5cb6.async.js +1 -0
  109. package/static/dist/{4859.6592cebb.async.js → 4859.97d6653c.async.js} +1 -1
  110. package/static/dist/{6013.4e38de36.async.js → 6013.db535339.async.js} +1 -1
  111. package/static/dist/6212.9e6d9913.async.js +1 -0
  112. package/static/dist/{6339.ab305e96.async.js → 6431.4603ad0e.async.js} +1 -1
  113. package/static/dist/{6872.42f939f1.async.js → 6872.a503ef55.async.js} +1 -1
  114. package/static/dist/7231.f7e5b668.async.js +1 -0
  115. package/static/dist/{7355.f9f263d8.async.js → 7355.fca746f5.async.js} +1 -1
  116. package/static/dist/{7508.7dcee91c.async.js → 7508.d90eac63.async.js} +1 -1
  117. package/static/dist/{7984.594296a5.async.js → 7984.eaac7402.async.js} +1 -1
  118. package/static/dist/8844.a0fef08e.async.js +1 -0
  119. package/static/dist/index.html +2 -2
  120. package/static/dist/layouts__index.633d3553.async.js +1 -0
  121. package/static/dist/preload_helper.cf7de3fa.js +1 -0
  122. package/static/dist/{src__pages__config__index.a22ff7dc.async.js → src__pages__config__index.9aba4054.async.js} +1 -1
  123. package/static/dist/src__pages__crontab__detail.86b2eebb.async.js +1 -0
  124. package/static/dist/src__pages__crontab__index.ae4e06f2.async.js +1 -0
  125. package/static/dist/{src__pages__crontab__logModal.831d5e4b.async.js → src__pages__crontab__logModal.930535e2.async.js} +1 -1
  126. package/static/dist/src__pages__crontab__modal.a2c8fdcc.async.js +1 -0
  127. package/static/dist/src__pages__crontab__viewCreateModal.7b4f9cbe.async.js +1 -0
  128. package/static/dist/src__pages__crontab__viewManageModal.cd454ea0.async.js +1 -0
  129. package/static/dist/src__pages__dashboard__index.243c5a35.async.js +1 -0
  130. package/static/dist/src__pages__dashboard__taskResultModal.7795d6e1.async.js +1 -0
  131. package/static/dist/src__pages__dependence__index.874d501f.async.js +1 -0
  132. package/static/dist/src__pages__dependence__logModal.154efe7a.async.js +1 -0
  133. package/static/dist/src__pages__dependence__modal.a29c1a0f.async.js +1 -0
  134. package/static/dist/{src__pages__diff__index.013b7c75.async.js → src__pages__diff__index.1714b941.async.js} +1 -1
  135. package/static/dist/src__pages__env__editNameModal.c13d47d2.async.js +1 -0
  136. package/static/dist/src__pages__env__index.fd6fd2b0.async.js +1 -0
  137. package/static/dist/src__pages__env__modal.4d71adb3.async.js +1 -0
  138. package/static/dist/src__pages__error__index.aae50c94.async.js +1 -0
  139. package/static/dist/src__pages__initialization__index.82a2e967.async.js +1 -0
  140. package/static/dist/src__pages__log__index.71250e0d.async.js +1 -0
  141. package/static/dist/{src__pages__login__index.8c813eb1.async.js → src__pages__login__index.a0fd5ed8.async.js} +1 -1
  142. package/static/dist/src__pages__script__editModal.22acdf7c.async.js +1 -0
  143. package/static/dist/src__pages__script__editNameModal.1a521cc0.async.js +1 -0
  144. package/static/dist/src__pages__script__index.a18b2692.async.js +1 -0
  145. package/static/dist/src__pages__script__renameModal.0ab029e7.async.js +1 -0
  146. package/static/dist/src__pages__script__saveModal.8965b74c.async.js +1 -0
  147. package/static/dist/src__pages__script__setting.35ad4f02.async.js +1 -0
  148. package/static/dist/src__pages__setting__appModal.7eaeb9d3.async.js +1 -0
  149. package/static/dist/{src__pages__setting__checkUpdate.34d773f2.async.js → src__pages__setting__checkUpdate.d175b154.async.js} +1 -1
  150. package/static/dist/src__pages__setting__clientIp.3a8711ed.async.js +1 -0
  151. package/static/dist/src__pages__setting__dependence.9c0f749b.async.js +1 -0
  152. package/static/dist/src__pages__setting__index.cb397741.async.js +1 -0
  153. package/static/dist/src__pages__setting__loginLog.e0a1f54d.async.js +1 -0
  154. package/static/dist/src__pages__setting__notification.2ffe4e5a.async.js +1 -0
  155. package/static/dist/src__pages__setting__other.3d0b8492.async.js +1 -0
  156. package/static/dist/{src__pages__setting__progress.8823ac90.async.js → src__pages__setting__progress.2ccae3d7.async.js} +1 -1
  157. package/static/dist/src__pages__setting__security.e2d71ebb.async.js +1 -0
  158. package/static/dist/src__pages__setting__systemLog.b3046955.async.js +1 -0
  159. package/static/dist/src__pages__subscription__index.43086a06.async.js +1 -0
  160. package/static/dist/src__pages__subscription__logModal.cdba5139.async.js +1 -0
  161. package/static/dist/src__pages__subscription__modal.38991e1e.async.js +1 -0
  162. package/static/dist/{umi.a54a59f6.js → umi.fc019050.js} +1 -1
  163. package/test/back/auth-security.test.cjs +74 -0
  164. package/test/back/build-provenance.test.cjs +150 -0
  165. package/test/back/cron-log-name.test.cjs +110 -0
  166. package/test/back/cron-validation.test.cjs +45 -0
  167. package/test/back/dashboard-failures.test.cjs +173 -0
  168. package/test/back/database-bootstrap.test.cjs +193 -0
  169. package/test/back/dependence-cache-status.test.cjs +125 -0
  170. package/test/back/deprecated-file-routes.test.cjs +82 -0
  171. package/test/back/ecosystem.test.cjs +28 -0
  172. package/test/back/env-name-parsing.test.cjs +96 -0
  173. package/test/back/execution-lifecycle.test.cjs +236 -0
  174. package/test/back/file-access-security.test.cjs +47 -0
  175. package/test/back/fileTreeListing.test.cjs +57 -0
  176. package/test/back/grpc-cron-response.test.cjs +60 -0
  177. package/test/back/http-exclusive-listen.test.cjs +31 -0
  178. package/test/back/http-security.test.cjs +213 -0
  179. package/test/back/listen-security.test.cjs +67 -0
  180. package/test/back/log-path-security.test.cjs +158 -0
  181. package/test/back/logReader.test.cjs +72 -0
  182. package/test/back/manual-execution.test.cjs +85 -0
  183. package/test/back/manual-stop-claim.test.cjs +220 -0
  184. package/test/back/metrics.test.cjs +34 -0
  185. package/test/back/monitoring.test.cjs +73 -0
  186. package/test/back/node-path-cache.test.cjs +173 -0
  187. package/test/back/node-path-lock.test.cjs +178 -0
  188. package/test/back/npm-publication.test.cjs +70 -0
  189. package/test/back/primary-apm.test.cjs +24 -0
  190. package/test/back/process-exit-state.test.cjs +81 -0
  191. package/test/back/process-stop-signal.test.cjs +77 -0
  192. package/test/back/protected-path-case.test.cjs +58 -0
  193. package/test/back/qlServiceLogCommand.test.cjs +128 -0
  194. package/test/back/retention.test.cjs +131 -0
  195. package/test/back/role-loading.test.cjs +118 -0
  196. package/test/back/schedule-health.test.cjs +86 -0
  197. package/test/back/scheduler-file-lock.test.cjs +51 -0
  198. package/test/back/scheduler-mutation.test.cjs +312 -0
  199. package/test/back/scheduler-readiness.test.cjs +85 -0
  200. package/test/back/scheduler-reconciliation.test.cjs +152 -0
  201. package/test/back/scheduler-rpc-timeout.test.cjs +49 -0
  202. package/test/back/schema-migrations.test.cjs +127 -0
  203. package/test/back/shell-api-parsing.test.cjs +184 -0
  204. package/test/back/sock-polling.test.cjs +297 -0
  205. package/test/back/sock-security.test.cjs +72 -0
  206. package/test/back/start-env-preservation.test.cjs +53 -0
  207. package/test/back/stop-failure-feedback.test.cjs +158 -0
  208. package/test/back/stop-race.test.cjs +167 -0
  209. package/test/back/subscription-cleanup.test.cjs +53 -0
  210. package/test/back/subscription-stop-state.test.cjs +66 -0
  211. package/test/back/system-dependence-cache.test.cjs +126 -0
  212. package/test/back/task-time.test.cjs +116 -0
  213. package/test/back/user-api.test.cjs +99 -0
  214. package/test/back/user-security.test.cjs +248 -0
  215. package/test/back/worker-apm.test.cjs +84 -0
  216. package/test/back/wpush-grpc.test.cjs +115 -0
  217. package/test/front/cron-log-pagination.test.cjs +214 -0
  218. package/test/front/http-auth.test.cjs +152 -0
  219. package/test/front/http-error.test.cjs +29 -0
  220. package/test/helpers/load-security-module.cjs +42 -0
  221. package/version.yaml +19 -34
  222. package/CLAUDE.md +0 -43
  223. package/static/dist/1147.62793604.async.js +0 -1
  224. package/static/dist/134.54df9e38.async.js +0 -1
  225. package/static/dist/2208.85285476.async.js +0 -1
  226. package/static/dist/2286.f371c743.async.js +0 -1
  227. package/static/dist/3191.545ab873.async.js +0 -1
  228. package/static/dist/4902.555f92ab.async.js +0 -1
  229. package/static/dist/5520.ff2cfd6b.async.js +0 -1
  230. package/static/dist/6431.c50479be.async.js +0 -1
  231. package/static/dist/8826.db34ad8d.async.js +0 -1
  232. package/static/dist/layouts__index.a7a2bfe0.async.js +0 -1
  233. package/static/dist/preload_helper.3048fe5b.js +0 -1
  234. package/static/dist/src__pages__crontab__detail.b98f0084.async.js +0 -1
  235. package/static/dist/src__pages__crontab__index.68e78a33.async.js +0 -1
  236. package/static/dist/src__pages__crontab__modal.f7041c7c.async.js +0 -1
  237. package/static/dist/src__pages__crontab__viewCreateModal.4d589f66.async.js +0 -1
  238. package/static/dist/src__pages__crontab__viewManageModal.0e317746.async.js +0 -1
  239. package/static/dist/src__pages__dashboard__index.58177357.async.js +0 -1
  240. package/static/dist/src__pages__dependence__index.b7bbc795.async.js +0 -1
  241. package/static/dist/src__pages__dependence__logModal.0681830b.async.js +0 -1
  242. package/static/dist/src__pages__dependence__modal.f7bb47ba.async.js +0 -1
  243. package/static/dist/src__pages__env__editNameModal.48715576.async.js +0 -1
  244. package/static/dist/src__pages__env__index.452cdc47.async.js +0 -1
  245. package/static/dist/src__pages__env__modal.e1234834.async.js +0 -1
  246. package/static/dist/src__pages__error__index.dedb2b90.async.js +0 -1
  247. package/static/dist/src__pages__initialization__index.22620a77.async.js +0 -1
  248. package/static/dist/src__pages__log__index.9c66639f.async.js +0 -1
  249. package/static/dist/src__pages__script__editModal.cbf4ec0e.async.js +0 -1
  250. package/static/dist/src__pages__script__editNameModal.532a3044.async.js +0 -1
  251. package/static/dist/src__pages__script__index.1fc20f22.async.js +0 -1
  252. package/static/dist/src__pages__script__renameModal.5cdde919.async.js +0 -1
  253. package/static/dist/src__pages__script__saveModal.5ffed35f.async.js +0 -1
  254. package/static/dist/src__pages__script__setting.1a82c6d7.async.js +0 -1
  255. package/static/dist/src__pages__setting__appModal.43b7758a.async.js +0 -1
  256. package/static/dist/src__pages__setting__dependence.9c04c79a.async.js +0 -1
  257. package/static/dist/src__pages__setting__index.7e070838.async.js +0 -1
  258. package/static/dist/src__pages__setting__loginLog.cea6056c.async.js +0 -1
  259. package/static/dist/src__pages__setting__notification.bac481c2.async.js +0 -1
  260. package/static/dist/src__pages__setting__other.707cfafe.async.js +0 -1
  261. package/static/dist/src__pages__setting__security.b7235753.async.js +0 -1
  262. package/static/dist/src__pages__setting__systemLog.b81a8c1d.async.js +0 -1
  263. package/static/dist/src__pages__subscription__index.d0ab2abc.async.js +0 -1
  264. package/static/dist/src__pages__subscription__logModal.3864b37f.async.js +0 -1
  265. package/static/dist/src__pages__subscription__modal.562448e2.async.js +0 -1
@@ -88,6 +88,10 @@ let DependenceService = class DependenceService {
88
88
  }
89
89
  async dependencies({ searchValue, type, status, }, sort = [], query = {}) {
90
90
  let condition = query;
91
+ const dependenceType = type && dependence_1.DependenceTypes[type] !== undefined
92
+ ? dependence_1.DependenceTypes[type]
93
+ : undefined;
94
+ await this.refreshInstalledStatuses(dependenceType);
91
95
  if (type && dependence_1.DependenceTypes[type] !== undefined) {
92
96
  condition.type = dependence_1.DependenceTypes[type];
93
97
  }
@@ -110,6 +114,49 @@ let DependenceService = class DependenceService {
110
114
  throw error;
111
115
  }
112
116
  }
117
+ async refreshInstalledStatuses(type) {
118
+ const cacheDependenceTypes = [
119
+ dependence_1.DependenceTypes.nodejs,
120
+ dependence_1.DependenceTypes.python3,
121
+ ];
122
+ if (type !== undefined && !cacheDependenceTypes.includes(type)) {
123
+ return;
124
+ }
125
+ const docs = await dependence_1.DependenceModel.findAll({
126
+ where: {
127
+ status: dependence_1.DependenceStatus.installed,
128
+ type: type === undefined ? { [sequelize_1.Op.in]: cacheDependenceTypes } : type,
129
+ },
130
+ });
131
+ const checks = await (0, util_1.concurrentRun)(docs.map((doc) => async () => {
132
+ return (await this.isDependenceInstalled(doc)) ? undefined : doc.id;
133
+ }), 5);
134
+ const missingIds = (checks || []).filter((id) => id !== undefined);
135
+ if (missingIds.length) {
136
+ await dependence_1.DependenceModel.update({ status: dependence_1.DependenceStatus.installFailed }, { where: { id: missingIds } });
137
+ }
138
+ }
139
+ async isDependenceInstalled(dependency) {
140
+ var _a;
141
+ let depName = dependency.name.trim();
142
+ const depVersionStr = dependence_1.versionDependenceCommandTypes[dependency.type];
143
+ let depVersion = '';
144
+ if (depName.includes(depVersionStr)) {
145
+ const symbolRegx = new RegExp(`(.*)${depVersionStr}([0-9\\.\\-\\+a-zA-Z]*)`);
146
+ const [, parsedName, parsedVersion] = depName.match(symbolRegx) || [];
147
+ if (parsedVersion && parsedName) {
148
+ depName = parsedName;
149
+ depVersion = parsedVersion;
150
+ }
151
+ }
152
+ const depInfo = (await (0, util_1.promiseExecSuccess)((0, util_1.getGetCommand)(dependency.type, depName)))
153
+ .replace(/\s{2,}/, ' ')
154
+ .replace(/\s+$/, '');
155
+ const nameMatches = (dependency.type === dependence_1.DependenceTypes.nodejs &&
156
+ ((_a = depInfo.split(' ')) === null || _a === void 0 ? void 0 : _a[0]) === depName) ||
157
+ dependency.type === dependence_1.DependenceTypes.python3;
158
+ return Boolean(depInfo && nameMatches && (!depVersion || depInfo.includes(depVersion)));
159
+ }
113
160
  installDependenceOneByOne(docs, isInstall = true, force = false) {
114
161
  docs.forEach((dep) => {
115
162
  this.installOrUninstallDependency(dep, isInstall, force);
@@ -67,7 +67,7 @@ let GrpcServerService = class GrpcServerService {
67
67
  const grpcPort = config_1.default.grpcPort;
68
68
  const hostsToTry = [
69
69
  config_1.default.bindHostGrpc,
70
- ...(config_1.default.bindHostGrpc !== '0.0.0.0' ? ['0.0.0.0'] : [])
70
+ ...(config_1.default.bindHostGrpc === '::' ? ['0.0.0.0'] : [])
71
71
  ];
72
72
  const bindAsync = (0, util_1.promisify)(this.server.bindAsync).bind(this.server);
73
73
  let lastError = null;
@@ -15,11 +15,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.HealthService = void 0;
16
16
  const typedi_1 = require("typedi");
17
17
  const logger_1 = __importDefault(require("../loaders/logger"));
18
- const grpc_1 = require("./grpc");
18
+ const client_1 = __importDefault(require("../schedule/client"));
19
19
  const http_1 = require("./http");
20
20
  let HealthService = class HealthService {
21
- constructor(grpcServerService, httpServerService) {
22
- this.grpcServerService = grpcServerService;
21
+ constructor(httpServerService) {
23
22
  this.httpServerService = httpServerService;
24
23
  this.startTime = Date.now();
25
24
  }
@@ -51,8 +50,7 @@ let HealthService = class HealthService {
51
50
  logger_1.default.error('HTTP server check failed:', err);
52
51
  }
53
52
  try {
54
- const grpcServer = this.grpcServerService.getServer();
55
- if (!grpcServer) {
53
+ if (!(await client_1.default.readiness.check())) {
56
54
  status.services.grpc = false;
57
55
  status.status = 'error';
58
56
  }
@@ -68,7 +66,6 @@ let HealthService = class HealthService {
68
66
  exports.HealthService = HealthService;
69
67
  exports.HealthService = HealthService = __decorate([
70
68
  (0, typedi_1.Service)(),
71
- __metadata("design:paramtypes", [grpc_1.GrpcServerService,
72
- http_1.HttpServerService])
69
+ __metadata("design:paramtypes", [http_1.HttpServerService])
73
70
  ], HealthService);
74
71
  //# sourceMappingURL=health.js.map
@@ -21,7 +21,7 @@ let HttpServerService = class HttpServerService {
21
21
  async initialize(expressApp, port) {
22
22
  const hostsToTry = [
23
23
  config_1.default.bindHost,
24
- ...(config_1.default.bindHost !== '0.0.0.0' ? ['0.0.0.0'] : [])
24
+ ...(config_1.default.bindHost === '::' ? ['0.0.0.0'] : [])
25
25
  ];
26
26
  let lastError = null;
27
27
  for (const host of hostsToTry) {
@@ -45,7 +45,13 @@ let HttpServerService = class HttpServerService {
45
45
  }
46
46
  async tryListen(expressApp, port, host) {
47
47
  return new Promise((resolve, reject) => {
48
- const server = expressApp.listen(port, host, () => {
48
+ // There is one HTTP worker; accepting here avoids primary IPC handoff
49
+ // for every connection. Restore shared listening for custom clusters.
50
+ const server = expressApp.listen({
51
+ port,
52
+ host,
53
+ exclusive: process.env.QL_HTTP_SHARED_LISTEN !== 'true',
54
+ }, () => {
49
55
  resolve(server);
50
56
  });
51
57
  server.on('error', (err) => {
@@ -15,7 +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 path_1 = __importDefault(require("path"));
18
+ const fileAccess_1 = require("../shared/fileAccess");
19
19
  const typedi_1 = require("typedi");
20
20
  const winston_1 = __importDefault(require("winston"));
21
21
  const config_1 = __importDefault(require("../config"));
@@ -24,8 +24,7 @@ let LogService = class LogService {
24
24
  this.logger = logger;
25
25
  }
26
26
  checkFilePath(filePath, fileName) {
27
- const finalPath = path_1.default.resolve(config_1.default.logPath, filePath, fileName);
28
- return finalPath.startsWith(config_1.default.logPath) ? finalPath : '';
27
+ return (0, fileAccess_1.resolveFileAccess)(config_1.default.logPath, [filePath || '', fileName], config_1.default.blackFileList);
29
28
  }
30
29
  };
31
30
  LogService = __decorate([
@@ -3,17 +3,19 @@ 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.metricsService = void 0;
6
+ exports.metricsService = exports.MetricsService = exports.MAX_METRIC_SAMPLES = void 0;
7
7
  const perf_hooks_1 = require("perf_hooks");
8
8
  const logger_1 = __importDefault(require("../loaders/logger"));
9
+ exports.MAX_METRIC_SAMPLES = 1000;
10
+ const METRIC_RETENTION_MS = 60 * 60 * 1000;
9
11
  class MetricsService {
10
12
  constructor() {
11
- this.metrics = [];
13
+ this.metrics = new Array(exports.MAX_METRIC_SAMPLES);
14
+ this.metricCount = 0;
15
+ this.nextMetricIndex = 0;
12
16
  // 定期清理旧数据
13
- setInterval(() => {
14
- const oneHourAgo = Date.now() - 3600000;
15
- this.metrics = this.metrics.filter(m => m.timestamp > oneHourAgo);
16
- }, 60000);
17
+ const cleanupTimer = setInterval(() => this.removeExpiredMetrics(), 60000);
18
+ cleanupTimer.unref();
17
19
  }
18
20
  static getInstance() {
19
21
  if (!MetricsService.instance) {
@@ -22,12 +24,14 @@ class MetricsService {
22
24
  return MetricsService.instance;
23
25
  }
24
26
  record(name, value, tags) {
25
- this.metrics.push({
27
+ this.metrics[this.nextMetricIndex] = {
26
28
  name,
27
29
  value,
28
30
  timestamp: Date.now(),
29
31
  tags,
30
- });
32
+ };
33
+ this.nextMetricIndex = (this.nextMetricIndex + 1) % exports.MAX_METRIC_SAMPLES;
34
+ this.metricCount = Math.min(this.metricCount + 1, exports.MAX_METRIC_SAMPLES);
31
35
  }
32
36
  measure(name, fn, tags) {
33
37
  const start = perf_hooks_1.performance.now();
@@ -50,25 +54,52 @@ class MetricsService {
50
54
  }
51
55
  }
52
56
  getMetrics(name, tags) {
53
- let filtered = this.metrics;
57
+ this.removeExpiredMetrics();
58
+ let filtered = this.getMetricSnapshot();
54
59
  if (name) {
55
- filtered = filtered.filter(m => m.name === name);
60
+ filtered = filtered.filter((m) => m.name === name);
56
61
  }
57
62
  if (tags) {
58
- filtered = filtered.filter(m => {
63
+ filtered = filtered.filter((m) => {
59
64
  if (!m.tags)
60
65
  return false;
61
66
  return Object.entries(tags).every(([key, value]) => m.tags[key] === value);
62
67
  });
63
68
  }
69
+ const values = filtered.map((metric) => metric.value);
64
70
  return {
65
71
  count: filtered.length,
66
- average: filtered.reduce((acc, curr) => acc + curr.value, 0) / filtered.length,
67
- min: Math.min(...filtered.map(m => m.value)),
68
- max: Math.max(...filtered.map(m => m.value)),
72
+ average: values.length
73
+ ? values.reduce((acc, value) => acc + value, 0) / values.length
74
+ : 0,
75
+ min: values.length ? Math.min(...values) : 0,
76
+ max: values.length ? Math.max(...values) : 0,
69
77
  metrics: filtered,
70
78
  };
71
79
  }
80
+ getMetricSnapshot() {
81
+ if (this.metricCount < exports.MAX_METRIC_SAMPLES) {
82
+ return this.metrics.slice(0, this.metricCount);
83
+ }
84
+ return [
85
+ ...this.metrics.slice(this.nextMetricIndex),
86
+ ...this.metrics.slice(0, this.nextMetricIndex),
87
+ ];
88
+ }
89
+ removeExpiredMetrics() {
90
+ const oldestTimestamp = Date.now() - METRIC_RETENTION_MS;
91
+ const retained = this.getMetricSnapshot().filter((metric) => metric.timestamp > oldestTimestamp);
92
+ if (retained.length === this.metricCount)
93
+ return;
94
+ this.metrics = new Array(exports.MAX_METRIC_SAMPLES);
95
+ this.metricCount = 0;
96
+ this.nextMetricIndex = 0;
97
+ for (const metric of retained) {
98
+ this.metrics[this.nextMetricIndex] = metric;
99
+ this.nextMetricIndex = (this.nextMetricIndex + 1) % exports.MAX_METRIC_SAMPLES;
100
+ this.metricCount++;
101
+ }
102
+ }
72
103
  report() {
73
104
  const report = {
74
105
  timestamp: Date.now(),
@@ -78,5 +109,6 @@ class MetricsService {
78
109
  return report;
79
110
  }
80
111
  }
112
+ exports.MetricsService = MetricsService;
81
113
  exports.metricsService = MetricsService.getInstance();
82
114
  //# sourceMappingURL=metrics.js.map
@@ -57,6 +57,7 @@ let NotificationService = class NotificationService {
57
57
  ['wxPusherBot', this.wxPusherBot],
58
58
  ['wxPusherSpt', this.wxPusherSpt],
59
59
  ['openiLink', this.openiLink],
60
+ ['wpush', this.wpush],
60
61
  ]);
61
62
  this.title = '';
62
63
  this.content = '';
@@ -779,6 +780,31 @@ let NotificationService = class NotificationService {
779
780
  throw new Error(error.response ? error.response.body : error);
780
781
  }
781
782
  }
783
+ async wpush() {
784
+ const { wpushApiKey, wpushChannel, wpushTopicCode } = this.params;
785
+ const url = 'https://api.wpush.cn/api/v1/send';
786
+ const json = {
787
+ apikey: `${wpushApiKey}`,
788
+ title: `${this.title}`,
789
+ content: `${this.content}`,
790
+ channel: `${wpushChannel || 'wechat'}`,
791
+ };
792
+ if (wpushTopicCode) {
793
+ json.topic_code = `${wpushTopicCode}`;
794
+ }
795
+ try {
796
+ const res = await http_1.httpClient.post(url, Object.assign(Object.assign({}, this.gotOption), { json }));
797
+ if (res.code === 0) {
798
+ return true;
799
+ }
800
+ else {
801
+ throw new Error(JSON.stringify(res));
802
+ }
803
+ }
804
+ catch (error) {
805
+ throw new Error(error.response ? error.response.body : error);
806
+ }
807
+ }
782
808
  };
783
809
  __decorate([
784
810
  (0, typedi_1.Inject)((type) => user_1.default),
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __importDefault = (this && this.__importDefault) || function (mod) {
9
+ return (mod && mod.__esModule) ? mod : { "default": mod };
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const promises_1 = __importDefault(require("fs/promises"));
13
+ const path_1 = __importDefault(require("path"));
14
+ const dayjs_1 = __importDefault(require("dayjs"));
15
+ const sequelize_1 = require("sequelize");
16
+ const typedi_1 = require("typedi");
17
+ const config_1 = __importDefault(require("../config"));
18
+ const cronStats_1 = require("../data/cronStats");
19
+ const data_1 = require("../data");
20
+ const runningInstance_1 = require("../data/runningInstance");
21
+ const system_1 = require("../data/system");
22
+ const retention_1 = require("../shared/retention");
23
+ function runningInstanceWhere(days) {
24
+ const cutoff = (0, dayjs_1.default)().subtract(days, 'day').unix();
25
+ return {
26
+ status: { [sequelize_1.Op.ne]: runningInstance_1.InstanceStatus.running },
27
+ [sequelize_1.Op.or]: [
28
+ { finished_at: { [sequelize_1.Op.lt]: cutoff } },
29
+ {
30
+ finished_at: { [sequelize_1.Op.is]: null },
31
+ started_at: { [sequelize_1.Op.lt]: cutoff },
32
+ },
33
+ ],
34
+ };
35
+ }
36
+ function cronStatWhere(days) {
37
+ return {
38
+ date: { [sequelize_1.Op.lt]: (0, dayjs_1.default)().subtract(days, 'day').format('YYYY-MM-DD') },
39
+ };
40
+ }
41
+ let RetentionService = class RetentionService {
42
+ async updatePolicy(policy) {
43
+ const normalized = (0, retention_1.normalizeRetentionPolicy)(policy);
44
+ const systemConfig = await system_1.SystemModel.findOne({
45
+ where: { type: system_1.AuthDataType.systemConfig },
46
+ });
47
+ if (!systemConfig) {
48
+ throw new Error('System config not found');
49
+ }
50
+ await system_1.SystemModel.update({
51
+ info: Object.assign(Object.assign({}, systemConfig.info), normalized),
52
+ }, { where: { id: systemConfig.id } });
53
+ return normalized;
54
+ }
55
+ async preview(request) {
56
+ const policy = (0, retention_1.normalizeRetentionPolicy)(request);
57
+ const dependenceCacheTypes = (request.dependenceCacheTypes || []).filter(retention_1.isDependenceCacheType);
58
+ const [runningInstances, cronStats, dependenceCaches] = await Promise.all([
59
+ policy.runningInstanceRetentionDays > 0
60
+ ? runningInstance_1.RunningInstanceModel.count({
61
+ where: runningInstanceWhere(policy.runningInstanceRetentionDays),
62
+ })
63
+ : 0,
64
+ policy.cronStatRetentionDays > 0
65
+ ? cronStats_1.CrontabStatModel.count({
66
+ where: cronStatWhere(policy.cronStatRetentionDays),
67
+ })
68
+ : 0,
69
+ Promise.all(dependenceCacheTypes.map(async (type) => ({
70
+ type,
71
+ bytes: await (0, retention_1.getDirectorySize)(path_1.default.join(config_1.default.dependenceCachePath, type)),
72
+ }))),
73
+ ]);
74
+ return {
75
+ policy,
76
+ runningInstances,
77
+ cronStats,
78
+ dependenceCaches,
79
+ dependenceCacheBytes: dependenceCaches.reduce((total, cache) => total + cache.bytes, 0),
80
+ compactDatabase: Boolean(request.compactDatabase),
81
+ };
82
+ }
83
+ async cleanup(request) {
84
+ const preview = await this.preview(request);
85
+ const deleted = await data_1.sequelize.transaction(async (transaction) => {
86
+ const runningInstances = preview.policy.runningInstanceRetentionDays > 0
87
+ ? await runningInstance_1.RunningInstanceModel.destroy({
88
+ where: runningInstanceWhere(preview.policy.runningInstanceRetentionDays),
89
+ transaction,
90
+ })
91
+ : 0;
92
+ const cronStats = preview.policy.cronStatRetentionDays > 0
93
+ ? await cronStats_1.CrontabStatModel.destroy({
94
+ where: cronStatWhere(preview.policy.cronStatRetentionDays),
95
+ transaction,
96
+ })
97
+ : 0;
98
+ return { runningInstances, cronStats };
99
+ });
100
+ const dependenceCaches = [];
101
+ for (const cache of preview.dependenceCaches) {
102
+ await promises_1.default.rm(path_1.default.join(config_1.default.dependenceCachePath, cache.type), {
103
+ recursive: true,
104
+ force: true,
105
+ });
106
+ dependenceCaches.push(cache);
107
+ }
108
+ if (request.compactDatabase &&
109
+ (deleted.runningInstances || deleted.cronStats)) {
110
+ await data_1.sequelize.query('VACUUM');
111
+ }
112
+ return {
113
+ deleted: Object.assign(Object.assign({}, deleted), { dependenceCaches, dependenceCacheBytes: preview.dependenceCacheBytes }),
114
+ compactedDatabase: Boolean(request.compactDatabase &&
115
+ (deleted.runningInstances || deleted.cronStats)),
116
+ };
117
+ }
118
+ };
119
+ RetentionService = __decorate([
120
+ (0, typedi_1.Service)()
121
+ ], RetentionService);
122
+ exports.default = RetentionService;
123
+ //# sourceMappingURL=retention.js.map
@@ -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);