@whyour/qinglong 2.21.0 → 2.23.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 (362) 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 +8 -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/development/node-cron-migration.md +49 -0
  19. package/docs/development/task-startup.md +78 -0
  20. package/docs/releases/2.22.0-validation.md +49 -0
  21. package/docs/releases/2.22.0.md +62 -0
  22. package/docs/releases/2.23.0.md +33 -0
  23. package/docs/script-history.md +53 -0
  24. package/ecosystem.config.js +10 -1
  25. package/package.json +19 -13
  26. package/sample/config.sample.sh +17 -2
  27. package/sample/notify.js +118 -0
  28. package/sample/notify.py +93 -0
  29. package/scripts/benchmark-execution.cjs +96 -0
  30. package/scripts/benchmark-script-history.cjs +39 -0
  31. package/scripts/publish-static.sh +34 -0
  32. package/scripts/sync-static.sh +20 -0
  33. package/scripts/wait-for-mirror.sh +214 -0
  34. package/scripts/write-build-info.cjs +27 -0
  35. package/shell/api.sh +96 -83
  36. package/shell/check.sh +59 -19
  37. package/shell/lang/en.sh +6 -0
  38. package/shell/lang/zh.sh +6 -0
  39. package/shell/node_path_cache.sh +136 -0
  40. package/shell/otask.sh +17 -10
  41. package/shell/preload/sitecustomize.js +11 -3
  42. package/shell/preload/sitecustomize.py +4 -2
  43. package/shell/share.sh +27 -10
  44. package/shell/start.sh +6 -3
  45. package/shell/task-timeout.sh +63 -0
  46. package/shell/task.sh +21 -9
  47. package/shell/update.sh +104 -98
  48. package/shell/upgrade.cjs +8 -0
  49. package/static/build/api/clientIp.js +42 -0
  50. package/static/build/api/config.js +9 -21
  51. package/static/build/api/cron.js +39 -3
  52. package/static/build/api/dashboard.js +50 -6
  53. package/static/build/api/env.js +17 -16
  54. package/static/build/api/health.js +2 -2
  55. package/static/build/api/index.js +4 -0
  56. package/static/build/api/log.js +39 -19
  57. package/static/build/api/open.js +2 -1
  58. package/static/build/api/retention.js +63 -0
  59. package/static/build/api/script.js +172 -25
  60. package/static/build/api/subscription.js +19 -8
  61. package/static/build/api/system.js +66 -12
  62. package/static/build/api/user.js +75 -15
  63. package/static/build/app.js +63 -54
  64. package/static/build/bootstrap/database.js +51 -0
  65. package/static/build/config/const.js +2 -0
  66. package/static/build/config/grpcCerts.js +93 -44
  67. package/static/build/config/index.js +0 -4
  68. package/static/build/config/share.js +5 -4
  69. package/static/build/config/subscription.js +19 -11
  70. package/static/build/config/util.js +142 -45
  71. package/static/build/data/cron.js +1 -0
  72. package/static/build/data/notify.js +18 -1
  73. package/static/build/data/sock.js +1 -0
  74. package/static/build/loaders/app.js +8 -6
  75. package/static/build/loaders/db.js +5 -35
  76. package/static/build/loaders/deps.js +30 -22
  77. package/static/build/loaders/express.js +46 -32
  78. package/static/build/loaders/initData.js +26 -33
  79. package/static/build/loaders/initFile.js +1 -1
  80. package/static/build/loaders/initTask.js +14 -3
  81. package/static/build/loaders/server.js +1 -1
  82. package/static/build/loaders/sock.js +72 -6
  83. package/static/build/middlewares/monitoring.js +12 -33
  84. package/static/build/middlewares/protectedPathCase.js +17 -0
  85. package/static/build/middlewares/uniqueConstraintError.js +15 -0
  86. package/static/build/protos/api.js +78 -2
  87. package/static/build/protos/cron.js +83 -5
  88. package/static/build/protos/health.js +1 -1
  89. package/static/build/schedule/addCron.js +67 -19
  90. package/static/build/schedule/api.js +5 -2
  91. package/static/build/schedule/client.js +56 -6
  92. package/static/build/schedule/delCron.js +11 -1
  93. package/static/build/schedule/health.js +72 -7
  94. package/static/build/schedule/setConcurrency.js +27 -0
  95. package/static/build/services/config.js +5 -43
  96. package/static/build/services/cron.js +389 -174
  97. package/static/build/services/dependence.js +66 -18
  98. package/static/build/services/env.js +1 -1
  99. package/static/build/services/grpc.js +4 -3
  100. package/static/build/services/health.js +4 -7
  101. package/static/build/services/http.js +9 -3
  102. package/static/build/services/log.js +2 -3
  103. package/static/build/services/metrics.js +46 -14
  104. package/static/build/services/notify.js +73 -5
  105. package/static/build/services/open.js +106 -31
  106. package/static/build/services/retention.js +123 -0
  107. package/static/build/services/schedule.js +77 -43
  108. package/static/build/services/script.js +4 -5
  109. package/static/build/services/scriptHistory.js +30 -0
  110. package/static/build/services/sshKey.js +39 -14
  111. package/static/build/services/subscription.js +161 -87
  112. package/static/build/services/system.js +116 -43
  113. package/static/build/services/user.js +255 -37
  114. package/static/build/shared/auth.js +22 -3
  115. package/static/build/shared/authMutation.js +17 -0
  116. package/static/build/shared/childProcess.js +82 -0
  117. package/static/build/shared/clientIp.js +27 -0
  118. package/static/build/shared/cronCommand.js +17 -0
  119. package/static/build/shared/cronSchedule.js +101 -0
  120. package/static/build/shared/cronScheduler.js +73 -0
  121. package/static/build/shared/errors.js +9 -0
  122. package/static/build/shared/fileAccess.js +60 -0
  123. package/static/build/shared/i18n.js +63 -4
  124. package/static/build/shared/logPath.js +15 -0
  125. package/static/build/shared/logReader.js +85 -0
  126. package/static/build/shared/logStreamManager.js +80 -60
  127. package/static/build/shared/loginThrottle.js +45 -0
  128. package/static/build/shared/pLimit.js +22 -8
  129. package/static/build/shared/password.js +30 -0
  130. package/static/build/shared/retention.js +58 -0
  131. package/static/build/shared/runCron.js +39 -17
  132. package/static/build/shared/schedulerMutationLock.js +44 -0
  133. package/static/build/shared/schedulerReadiness.js +82 -0
  134. package/static/build/shared/schemaMigrations.js +58 -0
  135. package/static/build/shared/scriptHistory.js +445 -0
  136. package/static/build/shared/shellQuote.js +11 -0
  137. package/static/build/shared/startupProcess.js +48 -0
  138. package/static/build/shared/store.js +7 -0
  139. package/static/build/shared/subscriptionMutationLock.js +34 -0
  140. package/static/build/shared/subscriptionPath.js +41 -0
  141. package/static/build/shared/subscriptionStorage.js +98 -0
  142. package/static/build/shared/trustProxy.js +119 -0
  143. package/static/build/shared/utils.js +2 -1
  144. package/static/build/token.js +3 -14
  145. package/static/build/validation/schedule.js +6 -12
  146. package/static/dist/{1885.e1ea09f6.async.js → 1885.b8f427bf.async.js} +1 -1
  147. package/static/dist/2031.6af40025.async.js +1 -0
  148. package/static/dist/2693.51c2636b.async.js +1 -0
  149. package/static/dist/{2890.9e373f5b.async.js → 2890.add55e85.async.js} +1 -1
  150. package/static/dist/2901.2ca95295.async.js +1 -0
  151. package/static/dist/292.264757f0.async.js +1 -0
  152. package/static/dist/3512.95e41255.async.js +1 -0
  153. package/static/dist/445.a65ff63b.async.js +1 -0
  154. package/static/dist/4736.1d2b5cb6.async.js +1 -0
  155. package/static/dist/{6013.4e38de36.async.js → 6013.db535339.async.js} +1 -1
  156. package/static/dist/6212.9e6d9913.async.js +1 -0
  157. package/static/dist/{6339.ab305e96.async.js → 6431.4603ad0e.async.js} +1 -1
  158. package/static/dist/{6872.42f939f1.async.js → 6872.a503ef55.async.js} +1 -1
  159. package/static/dist/7231.f7e5b668.async.js +1 -0
  160. package/static/dist/{7355.f9f263d8.async.js → 7355.fca746f5.async.js} +1 -1
  161. package/static/dist/{7508.7dcee91c.async.js → 7508.d90eac63.async.js} +1 -1
  162. package/static/dist/{7984.594296a5.async.js → 7984.eaac7402.async.js} +1 -1
  163. package/static/dist/8844.a0fef08e.async.js +1 -0
  164. package/static/dist/index.html +2 -2
  165. package/static/dist/layouts__index.633d3553.async.js +1 -0
  166. package/static/dist/preload_helper.01fcd534.js +1 -0
  167. package/static/dist/{src__pages__config__index.a22ff7dc.async.js → src__pages__config__index.9aba4054.async.js} +1 -1
  168. package/static/dist/src__pages__crontab__detail.86b2eebb.async.js +1 -0
  169. package/static/dist/src__pages__crontab__index.ae4e06f2.async.js +1 -0
  170. package/static/dist/{src__pages__crontab__logModal.0b8cce8c.async.js → src__pages__crontab__logModal.930535e2.async.js} +1 -1
  171. package/static/dist/src__pages__crontab__modal.a2c8fdcc.async.js +1 -0
  172. package/static/dist/src__pages__crontab__viewCreateModal.7b4f9cbe.async.js +1 -0
  173. package/static/dist/src__pages__crontab__viewManageModal.cd454ea0.async.js +1 -0
  174. package/static/dist/src__pages__dashboard__index.243c5a35.async.js +1 -0
  175. package/static/dist/src__pages__dashboard__taskResultModal.7795d6e1.async.js +1 -0
  176. package/static/dist/src__pages__dependence__index.874d501f.async.js +1 -0
  177. package/static/dist/src__pages__dependence__logModal.154efe7a.async.js +1 -0
  178. package/static/dist/src__pages__dependence__modal.0fa8b421.async.js +1 -0
  179. package/static/dist/src__pages__diff__index.b94e5dc5.async.js +1 -0
  180. package/static/dist/src__pages__env__editNameModal.c13d47d2.async.js +1 -0
  181. package/static/dist/src__pages__env__index.fd6fd2b0.async.js +1 -0
  182. package/static/dist/src__pages__env__modal.4d71adb3.async.js +1 -0
  183. package/static/dist/src__pages__error__index.aae50c94.async.js +1 -0
  184. package/static/dist/src__pages__initialization__index.82a2e967.async.js +1 -0
  185. package/static/dist/src__pages__log__index.71250e0d.async.js +1 -0
  186. package/static/dist/{src__pages__login__index.8c813eb1.async.js → src__pages__login__index.a0fd5ed8.async.js} +1 -1
  187. package/static/dist/src__pages__script__editModal.afabf073.async.js +1 -0
  188. package/static/dist/src__pages__script__editNameModal.789ad87b.async.js +1 -0
  189. package/static/dist/src__pages__script__historyDrawer.8c58d958.async.js +1 -0
  190. package/static/dist/src__pages__script__historyDrawer.a449193a.chunk.css +1 -0
  191. package/static/dist/src__pages__script__index.ab360776.chunk.css +1 -0
  192. package/static/dist/src__pages__script__index.fc575945.async.js +1 -0
  193. package/static/dist/src__pages__script__renameModal.0ab029e7.async.js +1 -0
  194. package/static/dist/src__pages__script__saveModal.8fca1a22.async.js +1 -0
  195. package/static/dist/src__pages__script__saveWithHistory.99ece830.async.js +1 -0
  196. package/static/dist/src__pages__script__setting.35ad4f02.async.js +1 -0
  197. package/static/dist/src__pages__setting__appModal.7eaeb9d3.async.js +1 -0
  198. package/static/dist/src__pages__setting__checkUpdate.d175b154.async.js +1 -0
  199. package/static/dist/src__pages__setting__clientIp.3a8711ed.async.js +1 -0
  200. package/static/dist/src__pages__setting__dependence.9c0f749b.async.js +1 -0
  201. package/static/dist/src__pages__setting__index.cb397741.async.js +1 -0
  202. package/static/dist/src__pages__setting__loginLog.e0a1f54d.async.js +1 -0
  203. package/static/dist/src__pages__setting__notification.2ffe4e5a.async.js +1 -0
  204. package/static/dist/src__pages__setting__other.3d0b8492.async.js +1 -0
  205. package/static/dist/{src__pages__setting__progress.8823ac90.async.js → src__pages__setting__progress.2ccae3d7.async.js} +1 -1
  206. package/static/dist/src__pages__setting__security.e2d71ebb.async.js +1 -0
  207. package/static/dist/src__pages__setting__systemLog.b3046955.async.js +1 -0
  208. package/static/dist/src__pages__subscription__index.43086a06.async.js +1 -0
  209. package/static/dist/src__pages__subscription__logModal.cdba5139.async.js +1 -0
  210. package/static/dist/src__pages__subscription__modal.30868ba8.async.js +1 -0
  211. package/static/dist/{umi.ca04a019.js → umi.3a24a9fa.js} +1 -1
  212. package/test/back/advisory-input-security.test.cjs +416 -0
  213. package/test/back/auth-security.test.cjs +74 -0
  214. package/test/back/build-provenance.test.cjs +150 -0
  215. package/test/back/code-scanning-security.test.cjs +189 -0
  216. package/test/back/cron-log-name.test.cjs +110 -0
  217. package/test/back/cron-macros.test.cjs +51 -0
  218. package/test/back/cron-schedule-compatibility.test.cjs +69 -0
  219. package/test/back/cron-scheduler-routing.test.cjs +59 -0
  220. package/test/back/cron-validation.test.cjs +45 -0
  221. package/test/back/dashboard-failures.test.cjs +173 -0
  222. package/test/back/database-bootstrap.test.cjs +193 -0
  223. package/test/back/dependence-cache-status.test.cjs +125 -0
  224. package/test/back/deprecated-file-routes.test.cjs +82 -0
  225. package/test/back/draft-path-security.test.cjs +235 -0
  226. package/test/back/ecosystem.test.cjs +28 -0
  227. package/test/back/env-import-security.test.cjs +91 -0
  228. package/test/back/env-name-parsing.test.cjs +96 -0
  229. package/test/back/execution-lifecycle.test.cjs +236 -0
  230. package/test/back/file-access-scope.test.cjs +180 -0
  231. package/test/back/file-access-security.test.cjs +47 -0
  232. package/test/back/fileTreeListing.test.cjs +57 -0
  233. package/test/back/grpc-cron-response.test.cjs +60 -0
  234. package/test/back/grpc-mtls-security.test.cjs +136 -0
  235. package/test/back/http-exclusive-listen.test.cjs +31 -0
  236. package/test/back/http-security.test.cjs +313 -0
  237. package/test/back/legacy-cron-recovery.test.cjs +76 -0
  238. package/test/back/linux-mirror-result.test.cjs +176 -0
  239. package/test/back/listen-security.test.cjs +68 -0
  240. package/test/back/log-path-security.test.cjs +158 -0
  241. package/test/back/logReader.test.cjs +72 -0
  242. package/test/back/manual-execution.test.cjs +85 -0
  243. package/test/back/manual-stop-claim.test.cjs +220 -0
  244. package/test/back/metrics.test.cjs +34 -0
  245. package/test/back/mirror-status.test.cjs +257 -0
  246. package/test/back/monitoring.test.cjs +73 -0
  247. package/test/back/node-cron-migration.test.cjs +65 -0
  248. package/test/back/node-path-cache.test.cjs +202 -0
  249. package/test/back/node-path-lock.test.cjs +182 -0
  250. package/test/back/npm-publication.test.cjs +70 -0
  251. package/test/back/preload-lazy-notify.test.cjs +168 -0
  252. package/test/back/primary-apm.test.cjs +24 -0
  253. package/test/back/process-exit-state.test.cjs +81 -0
  254. package/test/back/process-stop-signal.test.cjs +77 -0
  255. package/test/back/protected-path-case.test.cjs +58 -0
  256. package/test/back/qlServiceLogCommand.test.cjs +128 -0
  257. package/test/back/queued-cron-invalidation.test.cjs +98 -0
  258. package/test/back/restart-instance-recovery.test.cjs +116 -0
  259. package/test/back/retention.test.cjs +131 -0
  260. package/test/back/role-loading.test.cjs +118 -0
  261. package/test/back/schedule-health.test.cjs +86 -0
  262. package/test/back/scheduler-bulk-recovery.test.cjs +40 -0
  263. package/test/back/scheduler-concurrency.test.cjs +411 -0
  264. package/test/back/scheduler-file-lock.test.cjs +51 -0
  265. package/test/back/scheduler-mutation.test.cjs +312 -0
  266. package/test/back/scheduler-readiness.test.cjs +85 -0
  267. package/test/back/scheduler-reconciliation.test.cjs +206 -0
  268. package/test/back/scheduler-rpc-timeout.test.cjs +49 -0
  269. package/test/back/schema-migrations.test.cjs +127 -0
  270. package/test/back/script-file-access.test.cjs +210 -0
  271. package/test/back/script-history-api.test.cjs +551 -0
  272. package/test/back/script-history.test.cjs +383 -0
  273. package/test/back/shell-api-parsing.test.cjs +184 -0
  274. package/test/back/shell-translation-output.test.cjs +16 -0
  275. package/test/back/shell-upgrade.test.cjs +312 -0
  276. package/test/back/shellApiToken.test.cjs +151 -0
  277. package/test/back/sock-polling.test.cjs +297 -0
  278. package/test/back/sock-security.test.cjs +72 -0
  279. package/test/back/ssh-config-home.test.cjs +113 -0
  280. package/test/back/start-env-preservation.test.cjs +53 -0
  281. package/test/back/static-mirror-trigger.test.cjs +441 -0
  282. package/test/back/static-mirror.test.cjs +179 -0
  283. package/test/back/stop-failure-feedback.test.cjs +158 -0
  284. package/test/back/stop-race.test.cjs +171 -0
  285. package/test/back/subscription-cleanup.test.cjs +53 -0
  286. package/test/back/subscription-mutation-lock.test.cjs +83 -0
  287. package/test/back/subscription-review-regression.test.cjs +607 -0
  288. package/test/back/subscription-stop-state.test.cjs +66 -0
  289. package/test/back/subscription-storage-regression.test.cjs +553 -0
  290. package/test/back/system-dependence-cache.test.cjs +127 -0
  291. package/test/back/system-export-history.test.cjs +119 -0
  292. package/test/back/systemTokenRenewal.test.cjs +497 -0
  293. package/test/back/task-shell-lifecycle.test.cjs +194 -0
  294. package/test/back/task-time.test.cjs +116 -0
  295. package/test/back/unique-constraint-error.test.cjs +72 -0
  296. package/test/back/upgrade-guards.test.cjs +285 -0
  297. package/test/back/upgrade-lifecycle.test.cjs +288 -0
  298. package/test/back/upgrade-transaction.test.cjs +133 -0
  299. package/test/back/user-api.test.cjs +99 -0
  300. package/test/back/user-security.test.cjs +349 -0
  301. package/test/back/worker-apm.test.cjs +84 -0
  302. package/test/back/wpush-grpc.test.cjs +116 -0
  303. package/test/fixtures/legacy-cron.json +1371 -0
  304. package/test/front/cron-log-pagination.test.cjs +214 -0
  305. package/test/front/diff-file-routing.test.cjs +126 -0
  306. package/test/front/http-auth.test.cjs +152 -0
  307. package/test/front/http-error.test.cjs +29 -0
  308. package/test/front/script-history-save.test.cjs +121 -0
  309. package/test/helpers/load-security-module.cjs +42 -0
  310. package/test/helpers/upgrade-fixture.cjs +30 -0
  311. package/version.yaml +14 -34
  312. package/CLAUDE.md +0 -43
  313. package/static/dist/1147.c420132e.async.js +0 -1
  314. package/static/dist/134.54df9e38.async.js +0 -1
  315. package/static/dist/2096.6d98fd12.async.js +0 -1
  316. package/static/dist/2208.f7ba3dfa.async.js +0 -1
  317. package/static/dist/2286.164bb089.async.js +0 -1
  318. package/static/dist/3191.63263871.async.js +0 -1
  319. package/static/dist/4859.6592cebb.async.js +0 -1
  320. package/static/dist/4902.555f92ab.async.js +0 -1
  321. package/static/dist/5520.ff2cfd6b.async.js +0 -1
  322. package/static/dist/6431.c50479be.async.js +0 -1
  323. package/static/dist/6707.801b886b.async.js +0 -1
  324. package/static/dist/8826.2447a104.async.js +0 -1
  325. package/static/dist/layouts__index.a7a2bfe0.async.js +0 -1
  326. package/static/dist/preload_helper.0431c0f3.js +0 -1
  327. package/static/dist/src__pages__crontab__detail.b9c36808.async.js +0 -1
  328. package/static/dist/src__pages__crontab__index.fed99fd0.async.js +0 -1
  329. package/static/dist/src__pages__crontab__modal.f7041c7c.async.js +0 -1
  330. package/static/dist/src__pages__crontab__viewCreateModal.4d589f66.async.js +0 -1
  331. package/static/dist/src__pages__crontab__viewManageModal.0e317746.async.js +0 -1
  332. package/static/dist/src__pages__dashboard__index.b30f2f47.async.js +0 -1
  333. package/static/dist/src__pages__dependence__index.3d87ceac.async.js +0 -1
  334. package/static/dist/src__pages__dependence__logModal.0681830b.async.js +0 -1
  335. package/static/dist/src__pages__dependence__modal.11124896.async.js +0 -1
  336. package/static/dist/src__pages__diff__index.013b7c75.async.js +0 -1
  337. package/static/dist/src__pages__env__editNameModal.5d264b25.async.js +0 -1
  338. package/static/dist/src__pages__env__index.baa27d4e.async.js +0 -1
  339. package/static/dist/src__pages__env__modal.7f2ef1bc.async.js +0 -1
  340. package/static/dist/src__pages__error__index.f156b45e.async.js +0 -1
  341. package/static/dist/src__pages__initialization__index.e96d4ba8.async.js +0 -1
  342. package/static/dist/src__pages__log__index.e0978bae.async.js +0 -1
  343. package/static/dist/src__pages__script__editModal.cbf4ec0e.async.js +0 -1
  344. package/static/dist/src__pages__script__editNameModal.3e7e100d.async.js +0 -1
  345. package/static/dist/src__pages__script__index.2765d1b8.async.js +0 -1
  346. package/static/dist/src__pages__script__index.60b6f827.chunk.css +0 -1
  347. package/static/dist/src__pages__script__renameModal.5e987ef5.async.js +0 -1
  348. package/static/dist/src__pages__script__saveModal.3f9d23d6.async.js +0 -1
  349. package/static/dist/src__pages__script__setting.a535793a.async.js +0 -1
  350. package/static/dist/src__pages__setting__appModal.251cd14f.async.js +0 -1
  351. package/static/dist/src__pages__setting__checkUpdate.46efe057.async.js +0 -1
  352. package/static/dist/src__pages__setting__dependence.8a7a9529.async.js +0 -1
  353. package/static/dist/src__pages__setting__index.cc85fdfb.async.js +0 -1
  354. package/static/dist/src__pages__setting__loginLog.cea6056c.async.js +0 -1
  355. package/static/dist/src__pages__setting__notification.390fc905.async.js +0 -1
  356. package/static/dist/src__pages__setting__other.b22d2165.async.js +0 -1
  357. package/static/dist/src__pages__setting__security.598720a8.async.js +0 -1
  358. package/static/dist/src__pages__setting__systemLog.67406721.async.js +0 -1
  359. package/static/dist/src__pages__subscription__index.d0ab2abc.async.js +0 -1
  360. package/static/dist/src__pages__subscription__logModal.3864b37f.async.js +0 -1
  361. package/static/dist/src__pages__subscription__modal.3562c670.async.js +0 -1
  362. /package/static/dist/{4859.1b962b29.chunk.css → 292.1b962b29.chunk.css} +0 -0
@@ -15,14 +15,17 @@ 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 crypto_1 = require("crypto");
19
+ const cronSchedule_1 = require("../shared/cronSchedule");
20
+ const schedulerMutationLock_1 = require("../shared/schedulerMutationLock");
18
21
  const typedi_1 = require("typedi");
19
22
  const winston_1 = __importDefault(require("winston"));
20
23
  const config_1 = __importDefault(require("../config"));
24
+ const logPath_1 = require("../shared/logPath");
21
25
  const cron_1 = require("../data/cron");
22
26
  const runningInstance_1 = require("../data/runningInstance");
23
27
  const child_process_1 = require("child_process");
24
28
  const promises_1 = __importDefault(require("fs/promises"));
25
- const cron_parser_1 = __importDefault(require("cron-parser"));
26
29
  const util_1 = require("../config/util");
27
30
  const sequelize_1 = require("sequelize");
28
31
  const path_1 = __importDefault(require("path"));
@@ -37,17 +40,29 @@ const utils_1 = require("../shared/utils");
37
40
  const i18n_1 = require("../shared/i18n");
38
41
  const schedule_1 = require("../interface/schedule");
39
42
  const logStreamManager_1 = require("../shared/logStreamManager");
43
+ const childProcess_1 = require("../shared/childProcess");
40
44
  const lodash_1 = require("lodash");
45
+ const logReader_1 = require("../shared/logReader");
46
+ const fileAccess_1 = require("../shared/fileAccess");
41
47
  let CronService = class CronService {
42
48
  constructor(logger) {
43
49
  this.logger = logger;
44
50
  }
45
51
  isNodeCron(cron) {
46
52
  const { schedule, extra_schedules } = cron;
47
- if (Number(schedule === null || schedule === void 0 ? void 0 : schedule.split(/ +/).length) > 5 || (extra_schedules === null || extra_schedules === void 0 ? void 0 : extra_schedules.length)) {
48
- return true;
49
- }
50
- return false;
53
+ const fields = (schedule === null || schedule === void 0 ? void 0 : schedule.trim().split(/\s+/)) || [];
54
+ // System crontab only receives portable numeric five-field expressions.
55
+ // Extended syntax, macros and legacy shorthand use the Node scheduler.
56
+ return (fields.length !== 5 ||
57
+ /[^\d\s*,/\-]/.test(schedule || '') ||
58
+ Boolean(extra_schedules === null || extra_schedules === void 0 ? void 0 : extra_schedules.length) ||
59
+ // BusyBox treats N/step as a single value and doesn't support Sunday=7.
60
+ fields.some((field) => field.split(',').some((part) => /^\d+\//.test(part))) ||
61
+ fields[4].includes('7') ||
62
+ // BusyBox steps DOM from zero; its full-range day/week wildcard
63
+ // handling also differs from the legacy Node parser's OR semantics.
64
+ fields[2].includes('/') ||
65
+ (fields[2] !== '*' && fields[4] !== '*'));
51
66
  }
52
67
  get schedulerMode() {
53
68
  const env = process.env.QL_SCHEDULER;
@@ -97,59 +112,103 @@ let CronService = class CronService {
97
112
  return uniqPath;
98
113
  }
99
114
  async create(payload) {
100
- const tab = new cron_1.Crontab(payload);
101
- tab.saved = false;
102
- tab.log_name = await this.getLogName(tab);
103
- const doc = await this.insert(tab);
104
- if ((0, util_1.isDemoEnv)()) {
115
+ return (0, schedulerMutationLock_1.withSchedulerMutation)(async () => {
116
+ const tab = new cron_1.Crontab(payload);
117
+ tab.saved = false;
118
+ tab.log_name = await this.getLogName(tab);
119
+ const doc = await this.insert(tab);
120
+ if ((0, util_1.isDemoEnv)()) {
121
+ return doc;
122
+ }
123
+ if (this.shouldUseCronClient(doc)) {
124
+ try {
125
+ await client_1.default.addCron([
126
+ {
127
+ name: doc.name || '',
128
+ id: String(doc.id),
129
+ schedule: doc.schedule,
130
+ command: this.makeCommand(doc),
131
+ extra_schedules: doc.extra_schedules || [],
132
+ },
133
+ ]);
134
+ }
135
+ catch (error) {
136
+ // gRPC 注册失败时回滚 DB 记录,避免产生"僵尸任务"
137
+ // (DB 和 crontab.list 有记录但调度器永远不会执行)
138
+ await cron_1.CrontabModel.destroy({ where: { id: doc.id } });
139
+ this.logger.error('[crontab] Failed to register cron job in scheduler, task creation rolled back:', (error === null || error === void 0 ? void 0 : error.message) || error);
140
+ throw (0, schedulerMutationLock_1.schedulerRegistrationError)(`${(0, i18n_1.t)('调度器注册失败,任务创建已回滚')}: ${(error === null || error === void 0 ? void 0 : error.details) || (error === null || error === void 0 ? void 0 : error.message)}`, error);
141
+ }
142
+ }
143
+ await this.setCrontab();
105
144
  return doc;
106
- }
107
- if (this.shouldUseCronClient(doc)) {
108
- await client_1.default.addCron([
109
- {
110
- name: doc.name || '',
111
- id: String(doc.id),
112
- schedule: doc.schedule,
113
- command: this.makeCommand(doc),
114
- extra_schedules: doc.extra_schedules || [],
115
- },
116
- ]);
117
- }
118
- await this.setCrontab();
119
- return doc;
145
+ });
120
146
  }
121
147
  async insert(payload) {
122
148
  return await cron_1.CrontabModel.create(payload, { returning: true });
123
149
  }
124
150
  async update(payload) {
125
- const doc = await this.getDb({ id: payload.id });
126
- const tab = new cron_1.Crontab(Object.assign(Object.assign({}, doc), payload));
127
- tab.saved = false;
128
- tab.log_name = await this.getLogName(tab);
129
- const newDoc = await this.updateDb(tab);
130
- if (doc.isDisabled === 1 || (0, util_1.isDemoEnv)()) {
151
+ return (0, schedulerMutationLock_1.withSchedulerMutation)(async () => {
152
+ const doc = await this.getDb({ id: payload.id });
153
+ const tab = new cron_1.Crontab(Object.assign(Object.assign({}, doc), payload));
154
+ tab.saved = false;
155
+ tab.log_name = await this.getLogName(tab);
156
+ if (doc.isDisabled === 1 || (0, util_1.isDemoEnv)()) {
157
+ return await this.updateDb(tab);
158
+ }
159
+ // Keep the DB snapshot unchanged if deletion has an uncertain outcome.
160
+ // Recovery uses that snapshot after this mutation releases its lock.
161
+ await client_1.default.delCron([String(doc.id)]);
162
+ const newDoc = await this.updateDb(tab);
163
+ if (this.shouldUseCronClient(newDoc)) {
164
+ try {
165
+ await client_1.default.addCron([
166
+ {
167
+ name: doc.name || '',
168
+ id: String(newDoc.id),
169
+ schedule: newDoc.schedule,
170
+ command: this.makeCommand(newDoc),
171
+ extra_schedules: newDoc.extra_schedules || [],
172
+ },
173
+ ]);
174
+ }
175
+ catch (error) {
176
+ // gRPC 注册新任务失败 → 回滚 DB 到旧数据,并尝试恢复旧调度注册
177
+ await cron_1.CrontabModel.update((0, omit_1.default)(doc, ['queued_token']), {
178
+ where: { id: doc.id },
179
+ });
180
+ if (this.shouldUseCronClient(doc)) {
181
+ try {
182
+ await client_1.default.addCron([
183
+ {
184
+ name: doc.name || '',
185
+ id: String(doc.id),
186
+ schedule: doc.schedule,
187
+ command: this.makeCommand(doc),
188
+ extra_schedules: doc.extra_schedules || [],
189
+ },
190
+ ]);
191
+ }
192
+ catch (_recoveryError) {
193
+ this.logger.warn('[crontab] Failed to restore old cron job in scheduler after rollback:', (_recoveryError === null || _recoveryError === void 0 ? void 0 : _recoveryError.message) || _recoveryError);
194
+ }
195
+ }
196
+ this.logger.error('[crontab] Failed to register updated cron job in scheduler, update rolled back:', (error === null || error === void 0 ? void 0 : error.message) || error);
197
+ throw (0, schedulerMutationLock_1.schedulerRegistrationError)(`${(0, i18n_1.t)('调度器注册失败,任务更新已回滚')}: ${(error === null || error === void 0 ? void 0 : error.details) || (error === null || error === void 0 ? void 0 : error.message)}`, error);
198
+ }
199
+ }
200
+ await this.setCrontab();
131
201
  return newDoc;
132
- }
133
- await client_1.default.delCron([String(newDoc.id)]);
134
- if (this.shouldUseCronClient(newDoc)) {
135
- await client_1.default.addCron([
136
- {
137
- name: doc.name || '',
138
- id: String(newDoc.id),
139
- schedule: newDoc.schedule,
140
- command: this.makeCommand(newDoc),
141
- extra_schedules: newDoc.extra_schedules || [],
142
- },
143
- ]);
144
- }
145
- await this.setCrontab();
146
- return newDoc;
202
+ });
147
203
  }
148
204
  async updateDb(payload) {
149
205
  await cron_1.CrontabModel.update(payload, { where: { id: payload.id } });
150
206
  return await this.getDb({ id: payload.id });
151
207
  }
152
- async status({ ids, status, pid, log_path, last_running_time = 0, last_execution_time = 0, }) {
208
+ async status({ ids, status, pid, log_path, last_running_time = 0, last_execution_time = 0, exit_code, }) {
209
+ if (log_path && log_path !== '/dev/null') {
210
+ (0, logPath_1.resolveLogPath)(config_1.default.logPath, log_path);
211
+ }
153
212
  let options = {
154
213
  status,
155
214
  pid,
@@ -185,9 +244,13 @@ let CronService = class CronService {
185
244
  else if (status === cron_1.CrontabStatus.idle) {
186
245
  // Mark the matching running instance as finished
187
246
  const finishedAt = (0, dayjs_1.default)().unix();
247
+ const instanceStatus = exit_code !== undefined && exit_code !== null && exit_code !== 0
248
+ ? runningInstance_1.InstanceStatus.error
249
+ : runningInstance_1.InstanceStatus.finished;
188
250
  await runningInstance_1.RunningInstanceModel.update({
189
251
  finished_at: finishedAt,
190
- status: runningInstance_1.InstanceStatus.finished,
252
+ status: instanceStatus,
253
+ exit_code: exit_code !== null && exit_code !== void 0 ? exit_code : undefined,
191
254
  }, {
192
255
  where: {
193
256
  cron_id: id,
@@ -200,9 +263,11 @@ let CronService = class CronService {
200
263
  }
201
264
  }
202
265
  async remove(ids) {
203
- await cron_1.CrontabModel.destroy({ where: { id: ids } });
204
- await client_1.default.delCron(ids.map(String));
205
- await this.setCrontab();
266
+ return (0, schedulerMutationLock_1.withSchedulerMutation)(async () => {
267
+ await client_1.default.delCron(ids.map(String));
268
+ await cron_1.CrontabModel.destroy({ where: { id: ids } });
269
+ await this.setCrontab();
270
+ });
206
271
  }
207
272
  async pin(ids) {
208
273
  await cron_1.CrontabModel.update({ isPinned: 1 }, { where: { id: ids } });
@@ -445,31 +510,82 @@ let CronService = class CronService {
445
510
  return doc.get({ plain: true });
446
511
  }
447
512
  async run(ids) {
448
- await cron_1.CrontabModel.update({ status: cron_1.CrontabStatus.queued }, { where: { id: ids } });
513
+ const queuedToken = (0, crypto_1.randomUUID)();
514
+ await cron_1.CrontabModel.update({ status: cron_1.CrontabStatus.queued, queued_token: queuedToken }, { where: { id: ids } });
449
515
  ids.forEach((id) => {
450
- this.runSingle(id);
516
+ this.runSingle(id, queuedToken);
451
517
  });
452
518
  }
453
519
  async stop(ids) {
520
+ var _a, _b, _c, _d, _e;
454
521
  const docs = await cron_1.CrontabModel.findAll({ where: { id: ids } });
522
+ // Cancel the queued snapshot first, so a late spawn cannot claim it.
455
523
  for (const doc of docs) {
456
- // Kill all running instances of this task
524
+ if (doc.status === cron_1.CrontabStatus.queued) {
525
+ const [cancelled] = await cron_1.CrontabModel.update({ status: cron_1.CrontabStatus.idle, pid: null, queued_token: null }, {
526
+ where: {
527
+ id: doc.id,
528
+ status: cron_1.CrontabStatus.queued,
529
+ [sequelize_1.Op.and]: [
530
+ (0, sequelize_1.where)((0, sequelize_1.col)('log_path'), { [sequelize_1.Op.eq]: (_a = doc.log_path) !== null && _a !== void 0 ? _a : null }),
531
+ (0, sequelize_1.where)((0, sequelize_1.col)('queued_token'), {
532
+ [sequelize_1.Op.eq]: (_b = doc.queued_token) !== null && _b !== void 0 ? _b : null,
533
+ }),
534
+ ],
535
+ },
536
+ });
537
+ // A concurrent claim may have won; capture its PID before signalling.
538
+ if (!cancelled)
539
+ await doc.reload();
540
+ }
541
+ }
542
+ const stoppingInstances = await runningInstance_1.RunningInstanceModel.findAll({
543
+ attributes: ['id', 'pid', 'cron_id'],
544
+ where: { cron_id: ids, status: runningInstance_1.InstanceStatus.running },
545
+ });
546
+ const targets = new Set([
547
+ ...stoppingInstances.map((instance) => instance.pid),
548
+ ...docs
549
+ .filter((doc) => doc.status === cron_1.CrontabStatus.running)
550
+ .map((doc) => doc.pid),
551
+ ].filter((pid) => typeof pid === 'number' && pid > 0));
552
+ const stopped = new Set();
553
+ for (const pid of targets) {
457
554
  try {
458
- if (doc.pid) {
459
- await (0, util_1.killTask)(doc.pid);
460
- }
461
- const command = doc.command.replace(/\s+/g, ' ').trim();
462
- await (0, util_1.killAllTasks)(command);
463
- this.logger.info(`[panel][停止所有运行中的任务实例] 任务ID: ${doc.id}, 命令: ${command}`);
555
+ await (0, util_1.killTask)(pid, true);
556
+ stopped.add(pid);
464
557
  }
465
558
  catch (error) {
466
- this.logger.error(`[panel][停止任务失败] 任务ID: ${doc.id}, 错误: ${error}`);
559
+ this.logger.error('[panel][停止任务失败] PID: %s, 错误: %s', pid, (0, childProcess_1.asError)(error).message);
467
560
  }
468
561
  }
469
- // Mark all running instances as stopped
470
- const finishedAt = (0, dayjs_1.default)().unix();
471
- await runningInstance_1.RunningInstanceModel.update({ status: runningInstance_1.InstanceStatus.stopped, finished_at: finishedAt }, { where: { cron_id: ids, status: runningInstance_1.InstanceStatus.running } });
472
- await cron_1.CrontabModel.update({ status: cron_1.CrontabStatus.idle, pid: undefined }, { where: { id: ids } });
562
+ const stoppedIds = stoppingInstances
563
+ .filter((instance) => instance.pid && stopped.has(instance.pid))
564
+ .map((instance) => instance.id);
565
+ if (stoppedIds.length) {
566
+ await runningInstance_1.RunningInstanceModel.update({ status: runningInstance_1.InstanceStatus.stopped, finished_at: (0, dayjs_1.default)().unix() }, { where: { id: stoppedIds } });
567
+ }
568
+ for (const doc of docs) {
569
+ if (doc.status !== cron_1.CrontabStatus.running ||
570
+ (doc.pid && !stopped.has(doc.pid)))
571
+ continue;
572
+ const remaining = await runningInstance_1.RunningInstanceModel.count({
573
+ where: { cron_id: doc.id, status: runningInstance_1.InstanceStatus.running },
574
+ });
575
+ if (remaining)
576
+ continue;
577
+ await cron_1.CrontabModel.update({ status: cron_1.CrontabStatus.idle, pid: null, queued_token: null }, {
578
+ where: {
579
+ id: doc.id,
580
+ status: cron_1.CrontabStatus.running,
581
+ [sequelize_1.Op.and]: [
582
+ (0, sequelize_1.where)((0, sequelize_1.col)('queued_token'), { [sequelize_1.Op.eq]: (_c = doc.queued_token) !== null && _c !== void 0 ? _c : null }),
583
+ (0, sequelize_1.where)((0, sequelize_1.col)('pid'), { [sequelize_1.Op.eq]: (_d = doc.pid) !== null && _d !== void 0 ? _d : null }),
584
+ (0, sequelize_1.where)((0, sequelize_1.col)('log_path'), { [sequelize_1.Op.eq]: (_e = doc.log_path) !== null && _e !== void 0 ? _e : null }),
585
+ ],
586
+ },
587
+ });
588
+ }
473
589
  }
474
590
  async stopInstance(instanceId) {
475
591
  const instance = await runningInstance_1.RunningInstanceModel.findOne({
@@ -486,7 +602,7 @@ let CronService = class CronService {
486
602
  this.logger.error(`[panel][停止实例失败] 实例ID: ${instanceId}, PID: ${instance.pid}, 错误: ${error}`);
487
603
  }
488
604
  }
489
- await runningInstance_1.RunningInstanceModel.update({ status: runningInstance_1.InstanceStatus.stopped, finished_at: (0, dayjs_1.default)().unix() }, { where: { id: instanceId } });
605
+ await runningInstance_1.RunningInstanceModel.update({ status: runningInstance_1.InstanceStatus.stopped, finished_at: (0, dayjs_1.default)().unix(), exit_code: 143 }, { where: { id: instanceId } });
490
606
  // Check if there are still other running instances for this cron
491
607
  const otherRunning = await runningInstance_1.RunningInstanceModel.count({
492
608
  where: { cron_id: instance.cron_id, status: runningInstance_1.InstanceStatus.running },
@@ -496,122 +612,201 @@ let CronService = class CronService {
496
612
  }
497
613
  return { code: 200, message: (0, i18n_1.t)('实例已停止') };
498
614
  }
499
- async runSingle(cronId) {
500
- return pLimit_1.default.manualRunWithCronLimit(() => {
501
- return new Promise(async (resolve) => {
615
+ async runSingle(cronId, expectedToken) {
616
+ return pLimit_1.default.manualRunWithCronLimit(async () => {
617
+ var _a, _b;
618
+ let absolutePath;
619
+ let logPath;
620
+ let queuedLogPath;
621
+ let queuedToken = null;
622
+ let claimed = false;
623
+ try {
502
624
  const cron = await this.getDb({ id: cronId });
503
- const params = {
504
- name: cron.name,
505
- command: cron.command,
506
- schedule: cron.schedule,
507
- extra_schedules: cron.extra_schedules,
508
- };
509
- if (cron.status !== cron_1.CrontabStatus.queued) {
510
- resolve(params);
625
+ if (cron.status !== cron_1.CrontabStatus.queued ||
626
+ (expectedToken !== undefined && cron.queued_token !== expectedToken))
511
627
  return;
512
- }
513
- this.logger.info(`[panel][开始执行任务] 参数: ${JSON.stringify(params)}`);
514
- let { id, command, log_name } = cron;
628
+ queuedToken = (_a = cron.queued_token) !== null && _a !== void 0 ? _a : null;
629
+ queuedLogPath = (_b = cron.log_path) !== null && _b !== void 0 ? _b : null;
630
+ const { id, command, log_name } = cron;
515
631
  const uniqPath = log_name === '/dev/null' || !log_name
516
632
  ? await (0, util_1.getUniqPath)(command, `${id}`)
517
633
  : log_name;
518
634
  const logTime = (0, dayjs_1.default)().format('YYYY-MM-DD-HH-mm-ss-SSS');
519
- const logDirPath = path_1.default.resolve(config_1.default.logPath, `${uniqPath}`);
520
- await promises_1.default.mkdir(logDirPath, { recursive: true });
521
- const logPath = `${uniqPath}/${logTime}.log`;
522
- const absolutePath = path_1.default.resolve(config_1.default.logPath, `${logPath}`);
635
+ logPath = `${uniqPath}/${logTime}.log`;
636
+ absolutePath = (0, fileAccess_1.resolveFileAccess)(config_1.default.logPath, [logPath]);
637
+ if (!absolutePath)
638
+ throw new Error('Log path is outside the log directory');
639
+ await promises_1.default.mkdir(path_1.default.dirname(absolutePath), { recursive: true });
640
+ const outputPath = absolutePath;
523
641
  const cp = (0, cross_spawn_1.spawn)(`real_log_path=${logPath} no_delay=true ${this.makeCommand(cron, true)}`, { shell: '/bin/bash' });
524
- const startedAt = (0, dayjs_1.default)().unix();
525
- const instance = await runningInstance_1.RunningInstanceModel.create({
526
- cron_id: id,
527
- pid: cp.pid,
528
- log_path: logPath,
529
- started_at: startedAt,
530
- status: runningInstance_1.InstanceStatus.running,
531
- });
532
- await cron_1.CrontabModel.update({ status: cron_1.CrontabStatus.running, pid: cp.pid, log_path: logPath }, { where: { id } });
533
- cp.stdout.on('data', async (data) => {
534
- await logStreamManager_1.logStreamManager.write(absolutePath, data.toString());
535
- });
536
- cp.stderr.on('data', async (data) => {
537
- this.logger.info('[panel][执行任务失败] 命令: %s, 错误信息: %j', command, data.toString());
538
- await logStreamManager_1.logStreamManager.write(absolutePath, data.toString());
539
- });
540
- cp.on('error', async (err) => {
541
- this.logger.error('[panel][创建任务失败] 命令: %s, 错误信息: %j', command, err);
542
- await logStreamManager_1.logStreamManager.write(absolutePath, JSON.stringify(err));
642
+ // Install observers before the first await: very short children may already exit.
643
+ const { completed } = (0, childProcess_1.observeChildProcess)(cp, {
644
+ onStart: async () => {
645
+ try {
646
+ const [count] = await cron_1.CrontabModel.update({
647
+ status: cron_1.CrontabStatus.running,
648
+ pid: cp.pid,
649
+ log_path: logPath,
650
+ }, {
651
+ where: {
652
+ id,
653
+ status: cron_1.CrontabStatus.queued,
654
+ [sequelize_1.Op.and]: [
655
+ (0, sequelize_1.where)((0, sequelize_1.col)('queued_token'), { [sequelize_1.Op.eq]: queuedToken }),
656
+ (0, sequelize_1.where)((0, sequelize_1.col)('log_path'), { [sequelize_1.Op.eq]: queuedLogPath }),
657
+ ],
658
+ },
659
+ });
660
+ if (count !== 1)
661
+ throw new Error('Task was stopped or superseded before startup');
662
+ claimed = true;
663
+ }
664
+ catch (error) {
665
+ if (cp.pid)
666
+ await (0, util_1.killTask)(cp.pid, true);
667
+ throw error;
668
+ }
669
+ },
670
+ onStdout: (message) => logStreamManager_1.logStreamManager.write(outputPath, message),
671
+ onStderr: (message) => logStreamManager_1.logStreamManager.write(outputPath, message),
543
672
  });
544
- cp.on('exit', async (code) => {
545
- this.logger.info('[panel][执行任务结束] 参数: %s, 退出码: %j', JSON.stringify(params), code);
546
- await logStreamManager_1.logStreamManager.closeStream(absolutePath);
547
- const finishedAt = (0, dayjs_1.default)().unix();
548
- await runningInstance_1.RunningInstanceModel.update({
549
- finished_at: finishedAt,
550
- status: code === 0 ? runningInstance_1.InstanceStatus.finished : runningInstance_1.InstanceStatus.error,
551
- exit_code: code !== null && code !== void 0 ? code : undefined,
552
- }, { where: { id: instance.id } });
553
- // Only set cron to idle if no other running instances exist
554
- const otherRunning = await runningInstance_1.RunningInstanceModel.count({
555
- where: { cron_id: id, status: runningInstance_1.InstanceStatus.running },
673
+ const result = await completed;
674
+ if (result.error) {
675
+ this.logger.error('[panel][执行任务失败] 任务ID: %s, 错误: %s', id, result.error.message);
676
+ }
677
+ this.logger.info('[panel][执行任务结束] 任务ID: %s, 退出码: %j', id, result.code);
678
+ return Object.assign(Object.assign(Object.assign({}, cron), { pid: cp.pid }), result);
679
+ }
680
+ catch (error) {
681
+ this.logger.error('[panel][创建任务失败] 任务ID: %s, 错误: %s', cronId, (0, childProcess_1.asError)(error).message);
682
+ }
683
+ finally {
684
+ try {
685
+ if (absolutePath)
686
+ await logStreamManager_1.logStreamManager.closeStream(absolutePath);
687
+ }
688
+ catch (error) {
689
+ this.logger.error('[panel][关闭任务日志失败] %s', (0, childProcess_1.asError)(error).message);
690
+ }
691
+ try {
692
+ // Do not overwrite a newer run's state or its script-reported exit code.
693
+ await cron_1.CrontabModel.update({ status: cron_1.CrontabStatus.idle, pid: null, queued_token: null }, {
694
+ where: {
695
+ id: cronId,
696
+ [sequelize_1.Op.and]: (0, sequelize_1.where)((0, sequelize_1.col)('queued_token'), { [sequelize_1.Op.eq]: queuedToken }),
697
+ [sequelize_1.Op.or]: [
698
+ ...(queuedLogPath !== undefined && !claimed
699
+ ? [
700
+ {
701
+ status: cron_1.CrontabStatus.queued,
702
+ [sequelize_1.Op.and]: (0, sequelize_1.where)((0, sequelize_1.col)('log_path'), {
703
+ [sequelize_1.Op.eq]: queuedLogPath,
704
+ }),
705
+ },
706
+ ]
707
+ : []),
708
+ ...(claimed && logPath
709
+ ? [{ log_path: logPath, status: cron_1.CrontabStatus.running }]
710
+ : []),
711
+ ],
712
+ },
556
713
  });
557
- if (otherRunning === 0) {
558
- await cron_1.CrontabModel.update({ status: cron_1.CrontabStatus.idle, pid: undefined }, { where: { id } });
559
- }
560
- resolve(Object.assign(Object.assign({}, params), { pid: cp.pid, code }));
561
- });
562
- });
714
+ }
715
+ catch (error) {
716
+ this.logger.error('[panel][清理任务状态失败] %s', (0, childProcess_1.asError)(error).message);
717
+ }
718
+ }
563
719
  });
564
720
  }
565
721
  async disabled(ids) {
566
- await cron_1.CrontabModel.update({ isDisabled: 1 }, { where: { id: ids } });
567
- await client_1.default.delCron(ids.map(String));
568
- await this.setCrontab();
722
+ return (0, schedulerMutationLock_1.withSchedulerMutation)(async () => {
723
+ await client_1.default.delCron(ids.map(String));
724
+ await cron_1.CrontabModel.update({ isDisabled: 1 }, { where: { id: ids } });
725
+ await this.setCrontab();
726
+ });
569
727
  }
570
728
  async enabled(ids) {
571
- await cron_1.CrontabModel.update({ isDisabled: 0 }, { where: { id: ids } });
572
- const docs = await cron_1.CrontabModel.findAll({ where: { id: ids } });
573
- const crons = docs
574
- .filter((x) => this.shouldUseCronClient(x))
575
- .map((doc) => ({
576
- name: doc.name || '',
577
- id: String(doc.id),
578
- schedule: doc.schedule,
579
- command: this.makeCommand(doc),
580
- extra_schedules: doc.extra_schedules || [],
581
- }));
582
- if ((0, util_1.isDemoEnv)()) {
583
- return;
584
- }
585
- await client_1.default.addCron(crons);
586
- await this.setCrontab();
587
- }
588
- async log(id) {
729
+ return (0, schedulerMutationLock_1.withSchedulerMutation)(async () => {
730
+ await cron_1.CrontabModel.update({ isDisabled: 0 }, { where: { id: ids } });
731
+ const docs = await cron_1.CrontabModel.findAll({ where: { id: ids } });
732
+ const crons = docs
733
+ .filter((x) => this.shouldUseCronClient(x))
734
+ .map((doc) => ({
735
+ name: doc.name || '',
736
+ id: String(doc.id),
737
+ schedule: doc.schedule,
738
+ command: this.makeCommand(doc),
739
+ extra_schedules: doc.extra_schedules || [],
740
+ }));
741
+ if ((0, util_1.isDemoEnv)()) {
742
+ return;
743
+ }
744
+ try {
745
+ await client_1.default.addCron(crons);
746
+ }
747
+ catch (error) {
748
+ // gRPC 注册失败 → 回滚启用状态,避免 DB 显示已启用但调度器未注册
749
+ await cron_1.CrontabModel.update({ isDisabled: 1 }, { where: { id: ids } });
750
+ this.logger.error('[crontab] Failed to register cron job in scheduler, enable rolled back:', (error === null || error === void 0 ? void 0 : error.message) || error);
751
+ throw (0, schedulerMutationLock_1.schedulerRegistrationError)(`${(0, i18n_1.t)('调度器注册失败,任务启用已回滚')}: ${(error === null || error === void 0 ? void 0 : error.details) || (error === null || error === void 0 ? void 0 : error.message)}`, error);
752
+ }
753
+ await this.setCrontab();
754
+ });
755
+ }
756
+ async log(id, options = {}) {
589
757
  const doc = await this.getDb({ id });
590
758
  if (!doc) {
591
- return '';
759
+ return {
760
+ content: '',
761
+ status: 'empty',
762
+ offset: 0,
763
+ nextOffset: 0,
764
+ total: 0,
765
+ truncated: false,
766
+ };
592
767
  }
593
768
  if (doc.log_name === '/dev/null') {
594
- return '日志设置为忽略';
595
- }
596
- const absolutePath = path_1.default.resolve(config_1.default.logPath, `${doc.log_path}`);
769
+ return {
770
+ content: (0, i18n_1.t)('日志设置为忽略'),
771
+ status: 'ignored',
772
+ offset: 0,
773
+ nextOffset: 0,
774
+ total: 0,
775
+ truncated: false,
776
+ };
777
+ }
778
+ const absolutePath = doc.log_path
779
+ ? (0, logPath_1.resolveLogPath)(config_1.default.logPath, doc.log_path)
780
+ : '';
597
781
  const logFileExist = doc.log_path && (await (0, util_1.fileExist)(absolutePath));
598
782
  if (logFileExist) {
599
- return await (0, util_1.getFileContentByName)(`${absolutePath}`);
783
+ const chunk = await (0, logReader_1.readLogChunk)(`${absolutePath}`, options);
784
+ const isRunning = typeof doc.status === 'number' &&
785
+ [cron_1.CrontabStatus.running, cron_1.CrontabStatus.queued].includes(doc.status);
786
+ return Object.assign(Object.assign({}, chunk), { status: isRunning ? 'running' : 'completed' });
600
787
  }
601
788
  else {
602
- return typeof doc.status === 'number' &&
789
+ const status = typeof doc.status === 'number' &&
603
790
  [cron_1.CrontabStatus.queued, cron_1.CrontabStatus.running].includes(doc.status)
604
- ? '运行中...'
605
- : '日志不存在...';
791
+ ? 'running'
792
+ : 'notFound';
793
+ return {
794
+ content: status === 'running' ? (0, i18n_1.t)('运行中...') : (0, i18n_1.t)('日志不存在...'),
795
+ status,
796
+ offset: 0,
797
+ nextOffset: 0,
798
+ total: 0,
799
+ truncated: false,
800
+ };
606
801
  }
607
802
  }
608
803
  async logs(id) {
609
804
  const doc = await this.getDb({ id });
610
- if (!doc || !doc.log_path) {
805
+ if (!doc || !doc.log_path || doc.log_path === '/dev/null') {
611
806
  return [];
612
807
  }
613
808
  const relativeDir = path_1.default.dirname(`${doc.log_path}`);
614
- const dir = path_1.default.resolve(config_1.default.logPath, relativeDir);
809
+ const dir = path_1.default.dirname((0, logPath_1.resolveLogPath)(config_1.default.logPath, doc.log_path));
615
810
  const dirExist = await (0, util_1.fileExist)(dir);
616
811
  if (dirExist) {
617
812
  let files = await promises_1.default.readdir(dir);
@@ -700,7 +895,7 @@ let CronService = class CronService {
700
895
  const schedule = line.replace(command, '').trim();
701
896
  if (command &&
702
897
  schedule &&
703
- cron_parser_1.default.parse(schedule).hasNext()) {
898
+ (0, cronSchedule_1.isValidCronSchedule)(schedule)) {
704
899
  const name = namePrefix + '_' + index;
705
900
  const _crontab = await cron_1.CrontabModel.findOne({
706
901
  where: { command, schedule },
@@ -717,33 +912,53 @@ let CronService = class CronService {
717
912
  });
718
913
  });
719
914
  }
720
- async autosave_crontab() {
721
- const tabs = await this.crontabs();
722
- const regularCrons = tabs.data
723
- .filter((x) => x.isDisabled !== 1 &&
724
- this.shouldUseCronClient(x))
725
- .map((doc) => ({
726
- name: doc.name || '',
727
- id: String(doc.id),
728
- schedule: doc.schedule,
729
- command: this.makeCommand(doc),
730
- extra_schedules: doc.extra_schedules || [],
731
- }));
732
- if ((0, util_1.isDemoEnv)()) {
733
- await (0, utils_1.writeFileWithLock)(config_1.default.crontabFile, '');
734
- return;
735
- }
736
- await client_1.default.addCron(regularCrons);
737
- this.setCrontab(tabs);
915
+ async autosave_crontab(requireScheduler = false) {
916
+ return (0, schedulerMutationLock_1.withSchedulerMutation)(async () => {
917
+ const tabs = await this.crontabs();
918
+ // A bad persisted rule must not block startup or all other schedules.
919
+ // Keep the DB row editable; omit it from both runtime scheduler snapshots.
920
+ tabs.data = tabs.data.filter((doc) => {
921
+ if (doc.isDisabled === 1)
922
+ return true;
923
+ const invalidSchedules = (0, cronSchedule_1.getInvalidCronSchedules)(doc);
924
+ if (invalidSchedules.length === 0)
925
+ return true;
926
+ this.logger.warn('[crontab] Skipping task with invalid schedule (id=%s, name=%s): %s', doc.id, doc.name || '', JSON.stringify(invalidSchedules));
927
+ return false;
928
+ });
929
+ const regularCrons = tabs.data
930
+ .filter((x) => x.isDisabled !== 1 &&
931
+ this.shouldUseCronClient(x))
932
+ .map((doc) => ({
933
+ name: doc.name || '',
934
+ id: String(doc.id),
935
+ schedule: doc.schedule,
936
+ command: this.makeCommand(doc),
937
+ extra_schedules: doc.extra_schedules || [],
938
+ }));
939
+ if ((0, util_1.isDemoEnv)()) {
940
+ await (0, utils_1.writeFileWithLock)(config_1.default.crontabFile, '');
941
+ return;
942
+ }
943
+ // 先同步 crontab.list 与系统 crontab,确保其始终反映数据库真实状态。
944
+ // gRPC 调度注册为尽力而为:失败时不阻断文件同步,调度器重启后会重新注册。
945
+ // 这避免了因调度器短暂不可用导致 crontab.list 与数据库脱节(订阅更新误判任务已存在)。
946
+ await this.setCrontab(tabs);
947
+ try {
948
+ await client_1.default.addCron(regularCrons, requireScheduler);
949
+ }
950
+ catch (error) {
951
+ this.logger.warn('[crontab] Failed to register cron job in scheduler: %s', (error === null || error === void 0 ? void 0 : error.message) || error);
952
+ if (requireScheduler)
953
+ throw error;
954
+ }
955
+ });
738
956
  }
739
957
  async bootTask() {
740
958
  const tabs = await this.crontabs();
741
959
  const bootTasks = tabs.data.filter((x) => !x.isDisabled && this.isBootSchedule(x.schedule));
742
960
  if (bootTasks.length > 0) {
743
- await cron_1.CrontabModel.update({ status: cron_1.CrontabStatus.queued }, { where: { id: bootTasks.map((t) => t.id) } });
744
- for (const task of bootTasks) {
745
- this.runSingle(task.id);
746
- }
961
+ await this.run(bootTasks.map((task) => task.id));
747
962
  }
748
963
  }
749
964
  };