@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
@@ -38,6 +38,7 @@ const dayjs_1 = __importDefault(require("dayjs"));
38
38
  const pLimit_1 = __importDefault(require("../shared/pLimit"));
39
39
  const util_2 = require("../config/util");
40
40
  const const_1 = require("../config/const");
41
+ const i18n_1 = require("../shared/i18n");
41
42
  let DependenceService = class DependenceService {
42
43
  constructor(logger, sockService) {
43
44
  this.logger = logger;
@@ -87,6 +88,10 @@ let DependenceService = class DependenceService {
87
88
  }
88
89
  async dependencies({ searchValue, type, status, }, sort = [], query = {}) {
89
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);
90
95
  if (type && dependence_1.DependenceTypes[type] !== undefined) {
91
96
  condition.type = dependence_1.DependenceTypes[type];
92
97
  }
@@ -109,6 +114,49 @@ let DependenceService = class DependenceService {
109
114
  throw error;
110
115
  }
111
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
+ }
112
160
  installDependenceOneByOne(docs, isInstall = true, force = false) {
113
161
  docs.forEach((dep) => {
114
162
  this.installOrUninstallDependency(dep, isInstall, force);
@@ -183,7 +231,7 @@ let DependenceService = class DependenceService {
183
231
  }
184
232
  const depIds = [dependency.id];
185
233
  let depName = dependency.name.trim();
186
- const actionText = isInstall ? '安装' : '删除';
234
+ const actionText = isInstall ? (0, i18n_1.t)('安装') : (0, i18n_1.t)('删除');
187
235
  const socketMessageType = isInstall
188
236
  ? 'installDependence'
189
237
  : 'uninstallDependence';
@@ -197,11 +245,12 @@ let DependenceService = class DependenceService {
197
245
  if (!osType) {
198
246
  await dependence_1.DependenceModel.update({ status: dependence_1.DependenceStatus.installFailed }, { where: { id: depIds } });
199
247
  const startTime = (0, dayjs_1.default)();
200
- const message = `开始${actionText}依赖 ${depName},开始时间 ${startTime.format('YYYY-MM-DD HH:mm:ss')}\n\n当前系统不支持\n\n依赖${actionText}失败,结束时间 ${startTime.format('YYYY-MM-DD HH:mm:ss')},耗时 ${startTime.diff(startTime, 'second')} 秒`;
248
+ const message = (0, i18n_1.tf)('开始%s依赖 %s,开始时间 %s\n\n当前系统不支持\n\n依赖%s失败,结束时间 %s,耗时 %s 秒', actionText, depName, startTime.format('YYYY-MM-DD HH:mm:ss'), actionText, startTime.format('YYYY-MM-DD HH:mm:ss'), String(startTime.diff(startTime, 'second')));
201
249
  this.sockService.sendMessage({
202
250
  type: socketMessageType,
203
251
  message,
204
252
  references: depIds,
253
+ status: dependence_1.DependenceStatus.installFailed,
205
254
  });
206
255
  this.updateLog(depIds, message);
207
256
  return resolve(null);
@@ -221,11 +270,12 @@ let DependenceService = class DependenceService {
221
270
  : `${linuxCommand.uninstall} ${depName.trim()}`;
222
271
  }
223
272
  const startTime = (0, dayjs_1.default)();
224
- const message = `开始${actionText}依赖 ${depName},开始时间 ${startTime.format('YYYY-MM-DD HH:mm:ss')}\n\n`;
273
+ const message = (0, i18n_1.tf)('开始%s依赖 %s,开始时间 %s\n\n', actionText, depName, startTime.format('YYYY-MM-DD HH:mm:ss'));
225
274
  this.sockService.sendMessage({
226
275
  type: socketMessageType,
227
276
  message,
228
277
  references: depIds,
278
+ status,
229
279
  });
230
280
  this.updateLog(depIds, message);
231
281
  // 判断是否已经安装过依赖
@@ -254,11 +304,12 @@ let DependenceService = class DependenceService {
254
304
  isPythonDependence) &&
255
305
  (!depVersion || depInfo.includes(depVersion))) {
256
306
  const endTime = (0, dayjs_1.default)();
257
- const _message = `检测到已经安装 ${depName}\n\n${depInfo}\n\n跳过安装\n\n依赖${actionText}成功,结束时间 ${endTime.format('YYYY-MM-DD HH:mm:ss')},耗时 ${endTime.diff(startTime, 'second')} 秒`;
307
+ const _message = (0, i18n_1.tf)('检测到已经安装 %s\n\n%s\n\n跳过安装\n\n依赖%s成功,结束时间 %s,耗时 %s 秒', depName, depInfo, actionText, endTime.format('YYYY-MM-DD HH:mm:ss'), String(endTime.diff(startTime, 'second')));
258
308
  this.sockService.sendMessage({
259
309
  type: socketMessageType,
260
310
  message: _message,
261
311
  references: depIds,
312
+ status: dependence_1.DependenceStatus.installed,
262
313
  });
263
314
  this.updateLog(depIds, _message);
264
315
  await dependence_1.DependenceModel.update({ status: dependence_1.DependenceStatus.installed }, { where: { id: depIds } });
@@ -277,6 +328,7 @@ let DependenceService = class DependenceService {
277
328
  type: socketMessageType,
278
329
  message: data.toString(),
279
330
  references: depIds,
331
+ status,
280
332
  });
281
333
  this.updateLog(depIds, data.toString());
282
334
  });
@@ -285,6 +337,7 @@ let DependenceService = class DependenceService {
285
337
  type: socketMessageType,
286
338
  message: data.toString(),
287
339
  references: depIds,
340
+ status,
288
341
  });
289
342
  this.updateLog(depIds, data.toString());
290
343
  });
@@ -293,37 +346,32 @@ let DependenceService = class DependenceService {
293
346
  type: socketMessageType,
294
347
  message: JSON.stringify(err),
295
348
  references: depIds,
349
+ status,
296
350
  });
297
351
  this.updateLog(depIds, JSON.stringify(err));
298
352
  });
299
353
  cp.on('exit', async (code) => {
300
354
  const endTime = (0, dayjs_1.default)();
301
355
  const isSucceed = code === 0;
302
- const resultText = isSucceed ? '成功' : '失败';
303
- const message = `\n依赖${actionText}${resultText},结束时间 ${endTime.format('YYYY-MM-DD HH:mm:ss')},耗时 ${endTime.diff(startTime, 'second')} 秒`;
356
+ const resultText = isSucceed ? (0, i18n_1.t)('成功') : (0, i18n_1.t)('失败');
357
+ const message = '\n' +
358
+ (0, i18n_1.tf)('依赖%s%s,结束时间 %s,耗时 %s 秒', actionText, resultText, endTime.format('YYYY-MM-DD HH:mm:ss'), String(endTime.diff(startTime, 'second')));
359
+ const exitStatus = isSucceed
360
+ ? (isInstall ? dependence_1.DependenceStatus.installed : dependence_1.DependenceStatus.removed)
361
+ : (isInstall ? dependence_1.DependenceStatus.installFailed : dependence_1.DependenceStatus.removeFailed);
304
362
  this.sockService.sendMessage({
305
363
  type: socketMessageType,
306
364
  message,
307
365
  references: depIds,
366
+ status: exitStatus,
308
367
  });
309
368
  this.updateLog(depIds, message);
310
- let status;
311
- if (isSucceed) {
312
- status = isInstall
313
- ? dependence_1.DependenceStatus.installed
314
- : dependence_1.DependenceStatus.removed;
315
- }
316
- else {
317
- status = isInstall
318
- ? dependence_1.DependenceStatus.installFailed
319
- : dependence_1.DependenceStatus.removeFailed;
320
- }
321
369
  const docs = await dependence_1.DependenceModel.findAll({ where: { id: depIds } });
322
370
  const _docIds = docs
323
371
  .filter((x) => x.status !== dependence_1.DependenceStatus.cancelled)
324
372
  .map((x) => x.id);
325
373
  if (_docIds.length > 0) {
326
- await dependence_1.DependenceModel.update({ status }, { where: { id: _docIds } });
374
+ await dependence_1.DependenceModel.update({ status: exitStatus }, { where: { id: _docIds } });
327
375
  }
328
376
  // 如果删除依赖成功或者强制删除
329
377
  if ((isSucceed || force) && !isInstall) {
@@ -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;
@@ -75,7 +75,7 @@ let GrpcServerService = class GrpcServerService {
75
75
  try {
76
76
  const address = this.formatGrpcAddress(host, grpcPort);
77
77
  await bindAsync(address, credentials);
78
- logger_1.default.debug(`✌️ gRPC service started successfully on ${address}`);
78
+ logger_1.default.debug(`[boot] gRPC service started successfully on ${address}`);
79
79
  metrics_1.metricsService.record('grpc_service_start', 1, {
80
80
  port: grpcPort.toString(),
81
81
  host
@@ -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,13 +21,13 @@ 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) {
28
28
  try {
29
29
  const server = await this.tryListen(expressApp, port, host);
30
- logger_1.default.debug(`✌️ HTTP service started successfully on ${host}:${port}`);
30
+ logger_1.default.debug(`[boot] HTTP service started successfully on ${host}:${port}`);
31
31
  metrics_1.metricsService.record('http_service_start', 1, {
32
32
  port: port.toString(),
33
33
  host
@@ -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
@@ -55,7 +55,9 @@ let NotificationService = class NotificationService {
55
55
  ['chronocat', this.chronocat],
56
56
  ['ntfy', this.ntfy],
57
57
  ['wxPusherBot', this.wxPusherBot],
58
+ ['wxPusherSpt', this.wxPusherSpt],
58
59
  ['openiLink', this.openiLink],
60
+ ['wpush', this.wpush],
59
61
  ]);
60
62
  this.title = '';
61
63
  this.content = '';
@@ -306,7 +308,7 @@ let NotificationService = class NotificationService {
306
308
  {
307
309
  title: `${this.title}`,
308
310
  thumb_media_id,
309
- author: `智能助手`,
311
+ author: (0, i18n_1.t)('智能助手'),
310
312
  content_source_url: ``,
311
313
  content: `${this.content.replace(/\n/g, '<br/>')}`,
312
314
  digest: `${this.content}`,
@@ -322,7 +324,7 @@ let NotificationService = class NotificationService {
322
324
  title: `${this.title}`,
323
325
  description: `${this.content}`,
324
326
  url: 'https://github.com/whyour/qinglong',
325
- btntxt: '更多',
327
+ btntxt: (0, i18n_1.t)('更多'),
326
328
  },
327
329
  };
328
330
  break;
@@ -361,7 +363,7 @@ let NotificationService = class NotificationService {
361
363
  roomName: `${aibotkName}`,
362
364
  message: {
363
365
  type: 1,
364
- content: `【青龙快讯】\n\n${this.title}\n${this.content}`,
366
+ content: `【${(0, i18n_1.t)('青龙快讯')}】\n\n${this.title}\n${this.content}`,
365
367
  },
366
368
  };
367
369
  break;
@@ -372,7 +374,7 @@ let NotificationService = class NotificationService {
372
374
  name: `${aibotkName}`,
373
375
  message: {
374
376
  type: 1,
375
- content: `【青龙快讯】\n\n${this.title}\n${this.content}`,
377
+ content: `【${(0, i18n_1.t)('青龙快讯')}】\n\n${this.title}\n${this.content}`,
376
378
  },
377
379
  };
378
380
  break;
@@ -507,7 +509,7 @@ let NotificationService = class NotificationService {
507
509
  },
508
510
  });
509
511
  const info = await transporter.sendMail({
510
- from: `"青龙快讯" <${emailUser}>`,
512
+ from: `"${(0, i18n_1.t)('青龙快讯')}" <${emailUser}>`,
511
513
  to: recipients,
512
514
  subject: `${this.title}`,
513
515
  html: `${this.content.replace(/\n/g, '<br/>')}`,
@@ -620,6 +622,47 @@ let NotificationService = class NotificationService {
620
622
  throw new Error(error.response ? error.response.body : error);
621
623
  }
622
624
  }
625
+ async wxPusherSpt() {
626
+ const { wxPusherSptList } = this.params;
627
+ // 处理 SPT,将逗号分隔的字符串转为数组
628
+ const spts = wxPusherSptList
629
+ ? wxPusherSptList
630
+ .split(',')
631
+ .map((spt) => spt.trim())
632
+ .filter((spt) => spt)
633
+ : [];
634
+ if (!spts.length) {
635
+ throw new Error((0, i18n_1.t)('wxPusher SPT 不能为空'));
636
+ }
637
+ if (spts.length > 10) {
638
+ throw new Error((0, i18n_1.t)('wxPusher SPT 最多支持 10 个'));
639
+ }
640
+ const url = `https://wxpusher.zjiecode.com/api/send/message/simple-push`;
641
+ const json = {
642
+ content: `<h1>${this.title}</h1><br/><div style='white-space: pre-wrap;'>${this.content}</div>`,
643
+ summary: this.title,
644
+ contentType: 2,
645
+ };
646
+ // 单个 SPT 用 spt,多个用 sptList
647
+ if (spts.length === 1) {
648
+ json.spt = spts[0];
649
+ }
650
+ else {
651
+ json.sptList = spts;
652
+ }
653
+ try {
654
+ const res = await http_1.httpClient.post(url, Object.assign(Object.assign({}, this.gotOption), { json }));
655
+ if (res.code === 1000) {
656
+ return true;
657
+ }
658
+ else {
659
+ throw new Error(JSON.stringify(res));
660
+ }
661
+ }
662
+ catch (error) {
663
+ throw new Error(error.response ? error.response.body : error);
664
+ }
665
+ }
623
666
  async chronocat() {
624
667
  var _a, _b;
625
668
  const { chronocatURL, chronocatQQ, chronocatToken } = this.params;
@@ -737,6 +780,31 @@ let NotificationService = class NotificationService {
737
780
  throw new Error(error.response ? error.response.body : error);
738
781
  }
739
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
+ }
740
808
  };
741
809
  __decorate([
742
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