@whyour/qinglong 2.24.0 → 2.25.0-rc.1

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 (775) hide show
  1. package/cli/README.en.md +7 -7
  2. package/cli/README.md +7 -7
  3. package/cli/src/internal/maintenance/panelUpgrade.cjs +9 -3
  4. package/cli/src/internal/maintenance/upgradePrestart.cjs +21 -15
  5. package/package.json +7 -3
  6. package/sample/notify.py +78 -30
  7. package/shell/api.sh +58 -8
  8. package/shell/cron-command.py +127 -0
  9. package/shell/otask.sh +2 -1
  10. package/shell/preload/client.js +18 -10
  11. package/shell/preload/script-start.cjs +26 -0
  12. package/shell/preload/sitecustomize.js +6 -0
  13. package/shell/preload/sitecustomize.py +25 -0
  14. package/shell/share.sh +3 -3
  15. package/shell/subscription-files.py +171 -0
  16. package/shell/system-cron.sh +42 -0
  17. package/shell/task-timeout.sh +19 -1
  18. package/shell/task.sh +25 -3
  19. package/shell/update.sh +115 -147
  20. package/shell/upgrade-lock.yaml +2186 -1050
  21. package/static/build/api/cron.js +134 -17
  22. package/static/build/api/cron.js.map +1 -1
  23. package/static/build/api/dashboard.js +42 -50
  24. package/static/build/api/dashboard.js.map +1 -1
  25. package/static/build/api/dependence.js +52 -0
  26. package/static/build/api/dependence.js.map +1 -1
  27. package/static/build/api/health.js +0 -1
  28. package/static/build/api/health.js.map +1 -1
  29. package/static/build/api/log.js +10 -1
  30. package/static/build/api/log.js.map +1 -1
  31. package/static/build/api/open.js +2 -2
  32. package/static/build/api/open.js.map +1 -1
  33. package/static/build/api/script.js +11 -8
  34. package/static/build/api/script.js.map +1 -1
  35. package/static/build/api/system.js +2 -1
  36. package/static/build/api/system.js.map +1 -1
  37. package/static/build/api/user.js +0 -11
  38. package/static/build/api/user.js.map +1 -1
  39. package/static/build/app.js +41 -0
  40. package/static/build/app.js.map +1 -1
  41. package/static/build/bootstrap/systemCron.js +70 -0
  42. package/static/build/bootstrap/systemCron.js.map +1 -0
  43. package/static/build/config/index.js +0 -2
  44. package/static/build/config/index.js.map +1 -1
  45. package/static/build/config/util.js +75 -15
  46. package/static/build/config/util.js.map +1 -1
  47. package/static/build/data/cron.js +9 -0
  48. package/static/build/data/cron.js.map +1 -1
  49. package/static/build/data/cronStats.js +7 -0
  50. package/static/build/data/cronStats.js.map +1 -1
  51. package/static/build/data/index.js +23 -0
  52. package/static/build/data/index.js.map +1 -1
  53. package/static/build/data/open.js.map +1 -1
  54. package/static/build/data/runningInstance.js +2 -1
  55. package/static/build/data/runningInstance.js.map +1 -1
  56. package/static/build/loaders/express.js +59 -26
  57. package/static/build/loaders/express.js.map +1 -1
  58. package/static/build/loaders/initData.js +9 -10
  59. package/static/build/loaders/initData.js.map +1 -1
  60. package/static/build/protos/cron.js +83 -3
  61. package/static/build/protos/cron.js.map +1 -1
  62. package/static/build/schedule/addCron.js +62 -21
  63. package/static/build/schedule/addCron.js.map +1 -1
  64. package/static/build/schedule/client.js +1 -1
  65. package/static/build/schedule/client.js.map +1 -1
  66. package/static/build/schedule/registeredPlans.js +46 -0
  67. package/static/build/schedule/registeredPlans.js.map +1 -0
  68. package/static/build/services/cron.js +603 -256
  69. package/static/build/services/cron.js.map +1 -1
  70. package/static/build/services/dependence.js +57 -13
  71. package/static/build/services/dependence.js.map +1 -1
  72. package/static/build/services/env.js +13 -3
  73. package/static/build/services/env.js.map +1 -1
  74. package/static/build/services/grpc.js +2 -3
  75. package/static/build/services/grpc.js.map +1 -1
  76. package/static/build/services/log.js +1 -1
  77. package/static/build/services/log.js.map +1 -1
  78. package/static/build/services/open.js +10 -0
  79. package/static/build/services/open.js.map +1 -1
  80. package/static/build/services/retention.js +50 -18
  81. package/static/build/services/retention.js.map +1 -1
  82. package/static/build/services/system.js +3 -0
  83. package/static/build/services/system.js.map +1 -1
  84. package/static/build/shared/containerResources.js +80 -0
  85. package/static/build/shared/containerResources.js.map +1 -0
  86. package/static/build/shared/cronCommandProcess.js +39 -0
  87. package/static/build/shared/cronCommandProcess.js.map +1 -0
  88. package/static/build/shared/cronOperand.js +67 -0
  89. package/static/build/shared/cronOperand.js.map +1 -0
  90. package/static/build/shared/cronPreview.js +45 -0
  91. package/static/build/shared/cronPreview.js.map +1 -0
  92. package/static/build/shared/cronProcess.js +207 -0
  93. package/static/build/shared/cronProcess.js.map +1 -0
  94. package/static/build/shared/cronRecovery.js +24 -0
  95. package/static/build/shared/cronRecovery.js.map +1 -0
  96. package/static/build/shared/cronScheduler.js +71 -14
  97. package/static/build/shared/cronScheduler.js.map +1 -1
  98. package/static/build/shared/cronStatistics.js +53 -0
  99. package/static/build/shared/cronStatistics.js.map +1 -0
  100. package/static/build/shared/cronWaitQueue.js +38 -0
  101. package/static/build/shared/cronWaitQueue.js.map +1 -0
  102. package/static/build/shared/directoryPage.js +175 -0
  103. package/static/build/shared/directoryPage.js.map +1 -0
  104. package/static/build/shared/directoryPageRoute.js +40 -0
  105. package/static/build/shared/directoryPageRoute.js.map +1 -0
  106. package/static/build/shared/errors.js +9 -1
  107. package/static/build/shared/errors.js.map +1 -1
  108. package/static/build/shared/executionIdentity.js +19 -0
  109. package/static/build/shared/executionIdentity.js.map +1 -0
  110. package/static/build/shared/fileAccess.js +4 -1
  111. package/static/build/shared/fileAccess.js.map +1 -1
  112. package/static/build/shared/i18n.js +6 -0
  113. package/static/build/shared/i18n.js.map +1 -1
  114. package/static/build/shared/legacyDailyStatistics.js +159 -0
  115. package/static/build/shared/legacyDailyStatistics.js.map +1 -0
  116. package/static/build/shared/logReader.js +47 -15
  117. package/static/build/shared/logReader.js.map +1 -1
  118. package/static/build/shared/managedExit.cjs +462 -0
  119. package/static/build/shared/managedExit.cjs.map +1 -0
  120. package/static/build/shared/pLimit.js +34 -6
  121. package/static/build/shared/pLimit.js.map +1 -1
  122. package/static/build/shared/queueDiagnostics.js +100 -0
  123. package/static/build/shared/queueDiagnostics.js.map +1 -0
  124. package/static/build/shared/runCron.js +123 -20
  125. package/static/build/shared/runCron.js.map +1 -1
  126. package/static/build/shared/scheduleAudit.js +208 -0
  127. package/static/build/shared/scheduleAudit.js.map +1 -0
  128. package/static/build/shared/schemaMigrations.js +53 -1
  129. package/static/build/shared/schemaMigrations.js.map +1 -1
  130. package/static/build/shared/systemScheduleAudit.js +224 -0
  131. package/static/build/shared/systemScheduleAudit.js.map +1 -0
  132. package/static/build/shared/taskEnvName.js +79 -0
  133. package/static/build/shared/taskEnvName.js.map +1 -0
  134. package/static/build/shared/triggerHistory.js +1338 -0
  135. package/static/build/shared/triggerHistory.js.map +1 -0
  136. package/static/build/validation/schedule.js +5 -4
  137. package/static/build/validation/schedule.js.map +1 -1
  138. package/static/build-info.json +481 -422
  139. package/static/dist/{5876.93680102.async.js → 1013.f391f663.async.js} +1 -1
  140. package/static/dist/1042.79a1b7b9.async.js +1 -0
  141. package/static/dist/1042.79a1b7b9.async.js.gz +0 -0
  142. package/static/dist/1049.ce652253.async.js +1 -0
  143. package/static/dist/1088.a08a989c.async.js +1 -0
  144. package/static/dist/1088.a08a989c.async.js.gz +0 -0
  145. package/static/dist/1425.4f8f8a22.async.js +1 -0
  146. package/static/dist/1425.4f8f8a22.async.js.gz +0 -0
  147. package/static/dist/1470.f2ea8437.async.js +1 -0
  148. package/static/dist/1470.f2ea8437.async.js.gz +0 -0
  149. package/static/dist/{2783.0787fd60.async.js → 1493.d4855779.async.js} +1 -1
  150. package/static/dist/1498.9cbd5bb9.async.js +1 -0
  151. package/static/dist/1498.9cbd5bb9.async.js.gz +0 -0
  152. package/static/dist/1515.6153a790.async.js +1 -0
  153. package/static/dist/1515.6153a790.async.js.gz +0 -0
  154. package/static/dist/1535.e9e477b3.async.js +1 -0
  155. package/static/dist/1535.e9e477b3.async.js.gz +0 -0
  156. package/static/dist/1544.9287da56.async.js +1 -0
  157. package/static/dist/1666.70721323.async.js +1 -0
  158. package/static/dist/1666.70721323.async.js.gz +0 -0
  159. package/static/dist/{5878.32535c39.async.js → 1739.62d88535.async.js} +1 -1
  160. package/static/dist/1782.1157c5a1.async.js +1 -0
  161. package/static/dist/1782.1157c5a1.async.js.gz +0 -0
  162. package/static/dist/1817.b289fb2e.async.js +1 -0
  163. package/static/dist/{6841.e92e9802.async.js → 1821.30f17ea7.async.js} +1 -1
  164. package/static/dist/1834.4c8d8590.async.js +1 -0
  165. package/static/dist/1834.4c8d8590.async.js.gz +0 -0
  166. package/static/dist/{7661.6684ddda.async.js → 1965.7049837c.async.js} +1 -1
  167. package/static/dist/2021.17d1b18c.async.js +1 -0
  168. package/static/dist/2021.17d1b18c.async.js.gz +0 -0
  169. package/static/dist/{4462.02fd0a33.async.js → 2133.4f1a8aa3.async.js} +1 -1
  170. package/static/dist/{3730.3654e8fa.async.js → 2165.4f689026.async.js} +1 -1
  171. package/static/dist/{2506.a6334794.async.js → 2171.06fa2587.async.js} +1 -1
  172. package/static/dist/219.6cd1eb3b.async.js +1 -0
  173. package/static/dist/219.6cd1eb3b.async.js.gz +0 -0
  174. package/static/dist/2213.d93a456d.async.js +1 -0
  175. package/static/dist/2213.d93a456d.async.js.gz +0 -0
  176. package/static/dist/{591.1c6b5df7.async.js → 2237.d999da2f.async.js} +1 -1
  177. package/static/dist/2276.370615e4.chunk.css +1 -0
  178. package/static/dist/2276.370615e4.chunk.css.gz +0 -0
  179. package/static/dist/2276.8300bac5.async.js +1 -0
  180. package/static/dist/2276.8300bac5.async.js.gz +0 -0
  181. package/static/dist/2324.20bd306f.async.js +1 -0
  182. package/static/dist/2324.20bd306f.async.js.gz +0 -0
  183. package/static/dist/2326.c2d87fc3.async.js +1 -0
  184. package/static/dist/2326.c2d87fc3.async.js.gz +0 -0
  185. package/static/dist/2373.02455a57.async.js +1 -0
  186. package/static/dist/2424.3f14675e.async.js +1 -0
  187. package/static/dist/2424.3f14675e.async.js.gz +0 -0
  188. package/static/dist/2497.b8f4f24c.async.js +1 -0
  189. package/static/dist/263.a1f04da7.async.js +1 -0
  190. package/static/dist/263.a1f04da7.async.js.gz +0 -0
  191. package/static/dist/{4821.64537e48.async.js → 2733.9e525e7d.async.js} +1 -1
  192. package/static/dist/{8416.69691e31.async.js → 2773.ab860583.async.js} +1 -1
  193. package/static/dist/2789.0f375c90.async.js +1 -0
  194. package/static/dist/2789.0f375c90.async.js.gz +0 -0
  195. package/static/dist/2805.ab342353.async.js +1 -0
  196. package/static/dist/2805.ab342353.async.js.gz +0 -0
  197. package/static/dist/2835.bf469780.async.js +1 -0
  198. package/static/dist/2835.bf469780.async.js.gz +0 -0
  199. package/static/dist/2840.bd6bfc2f.async.js +1 -0
  200. package/static/dist/2840.bd6bfc2f.async.js.gz +0 -0
  201. package/static/dist/{5363.2fedc735.async.js → 2953.5bf0d335.async.js} +1 -1
  202. package/static/dist/2985.0dcb5919.async.js +1 -0
  203. package/static/dist/305.bda7c12a.async.js +1 -0
  204. package/static/dist/305.bda7c12a.async.js.gz +0 -0
  205. package/static/dist/314.a83f680b.async.js +1 -0
  206. package/static/dist/{5325.54777fe5.async.js → 3141.3981e6db.async.js} +1 -1
  207. package/static/dist/325.76b96b5f.async.js +1 -0
  208. package/static/dist/{4756.64d6d0a4.async.js → 3333.4f9d1af4.async.js} +1 -1
  209. package/static/dist/{7540.6bb57f5f.async.js → 3394.b3df0cfe.async.js} +1 -1
  210. package/static/dist/{6638.87a163d2.async.js → 3456.edb5cb58.async.js} +1 -1
  211. package/static/dist/3456.edb5cb58.async.js.gz +0 -0
  212. package/static/dist/{1969.d61ba5fb.async.js → 3679.83e4f620.async.js} +1 -1
  213. package/static/dist/{5759.45438497.async.js → 3765.0fae92bd.async.js} +1 -1
  214. package/static/dist/3875.f1302872.async.js +1 -0
  215. package/static/dist/3875.f1302872.async.js.gz +0 -0
  216. package/static/dist/{5232.f4b06476.async.js → 3877.8ee12c42.async.js} +1 -1
  217. package/static/dist/4069.dbfcdd8a.async.js +1 -0
  218. package/static/dist/4210.b6c5d985.async.js +1 -0
  219. package/static/dist/4210.b6c5d985.async.js.gz +0 -0
  220. package/static/dist/4293.6d8f5759.async.js +1 -0
  221. package/static/dist/{9082.9f6c6520.async.js → 4319.856b86a6.async.js} +1 -1
  222. package/static/dist/{8060.8b699029.async.js → 4351.2ba3f7f8.async.js} +1 -1
  223. package/static/dist/{4944.3be3e188.async.js → 4357.b7e15ffb.async.js} +1 -1
  224. package/static/dist/4427.fbb31d76.async.js +1 -0
  225. package/static/dist/4428.24e59f1f.async.js +1 -0
  226. package/static/dist/4428.24e59f1f.async.js.gz +0 -0
  227. package/static/dist/4429.66d7e41f.async.js +1 -0
  228. package/static/dist/{3617.b7d4b2ed.async.js → 4609.286111c5.async.js} +1 -1
  229. package/static/dist/4659.0597a258.async.js +1 -0
  230. package/static/dist/{9187.4bacb25e.async.js → 4719.cc69b2f2.async.js} +1 -1
  231. package/static/dist/{4507.8541bc6d.async.js → 4725.3fd118d4.async.js} +1 -1
  232. package/static/dist/{7846.7d689939.async.js → 4754.dad00196.async.js} +1 -1
  233. package/static/dist/4898.826fa9f5.async.js +1 -0
  234. package/static/dist/4898.826fa9f5.async.js.gz +0 -0
  235. package/static/dist/4956.38e3a6c2.async.js +1 -0
  236. package/static/dist/4956.38e3a6c2.async.js.gz +0 -0
  237. package/static/dist/4994.ef6ca2ba.async.js +1 -0
  238. package/static/dist/4994.ef6ca2ba.async.js.gz +0 -0
  239. package/static/dist/5029.322132ca.async.js +1 -0
  240. package/static/dist/5101.2d8cc112.async.js +1 -0
  241. package/static/dist/5177.19a47f75.async.js +1 -0
  242. package/static/dist/5307.b95ee226.async.js +1 -0
  243. package/static/dist/{8394.452e865e.async.js → 5323.a4649b86.async.js} +1 -1
  244. package/static/dist/5420.13afeb19.async.js +1 -0
  245. package/static/dist/5420.13afeb19.async.js.gz +0 -0
  246. package/static/dist/5456.c828e5b4.async.js +1 -0
  247. package/static/dist/5456.c828e5b4.async.js.gz +0 -0
  248. package/static/dist/{7272.1c73bcc5.async.js → 5573.2b4c3f53.async.js} +1 -1
  249. package/static/dist/5646.f0ebc19e.async.js +1 -0
  250. package/static/dist/5646.f0ebc19e.async.js.gz +0 -0
  251. package/static/dist/5672.0a858802.async.js +1 -0
  252. package/static/dist/5677.7969d6a6.async.js +1 -0
  253. package/static/dist/5677.7969d6a6.async.js.gz +0 -0
  254. package/static/dist/{2843.e968a7af.async.js → 5735.5ac81392.async.js} +1 -1
  255. package/static/dist/{3711.9814cb8c.async.js → 5829.858a67a0.async.js} +1 -1
  256. package/static/dist/5888.2e92bdee.async.js +1 -0
  257. package/static/dist/5888.2e92bdee.async.js.gz +0 -0
  258. package/static/dist/5904.f23cb541.async.js +1 -0
  259. package/static/dist/5904.f23cb541.async.js.gz +0 -0
  260. package/static/dist/5979.41d8d93d.async.js +1 -0
  261. package/static/dist/5979.41d8d93d.async.js.gz +0 -0
  262. package/static/dist/{4481.4d51cf36.async.js → 5983.843a4e79.async.js} +1 -1
  263. package/static/dist/{1212.f87fd07a.async.js → 5985.de461b85.async.js} +1 -1
  264. package/static/dist/5985.de461b85.async.js.gz +0 -0
  265. package/static/dist/6049.f95bb9f8.async.js +1 -0
  266. package/static/dist/6049.f95bb9f8.async.js.gz +0 -0
  267. package/static/dist/6070.b1fcc5b4.async.js +1 -0
  268. package/static/dist/6070.b1fcc5b4.async.js.gz +0 -0
  269. package/static/dist/6107.f62df6ae.async.js +1 -0
  270. package/static/dist/6107.f62df6ae.async.js.gz +0 -0
  271. package/static/dist/615.2c53dc81.async.js +1 -0
  272. package/static/dist/615.2c53dc81.async.js.gz +0 -0
  273. package/static/dist/617.d89eb389.async.js +1 -0
  274. package/static/dist/617.d89eb389.async.js.gz +0 -0
  275. package/static/dist/6186.b1eb8fa3.async.js +1 -0
  276. package/static/dist/6186.b1eb8fa3.async.js.gz +0 -0
  277. package/static/dist/{9853.695fdd64.async.js → 6262.d9fc0702.async.js} +1 -1
  278. package/static/dist/6397.cf1917b0.async.js +1 -0
  279. package/static/dist/64.5fe1900f.async.js +1 -0
  280. package/static/dist/{8526.bb556c43.async.js → 6413.3f27247d.async.js} +1 -1
  281. package/static/dist/{8038.58b0571f.async.js → 6437.65f88a1e.async.js} +1 -1
  282. package/static/dist/6457.ef8eb546.async.js +1 -0
  283. package/static/dist/6457.ef8eb546.async.js.gz +0 -0
  284. package/static/dist/6508.59f796e6.async.js +1 -0
  285. package/static/dist/6508.59f796e6.async.js.gz +0 -0
  286. package/static/dist/6511.b01e1a63.async.js +1 -0
  287. package/static/dist/6552.e15660f5.async.js +1 -0
  288. package/static/dist/6552.e15660f5.async.js.gz +0 -0
  289. package/static/dist/6593.6b4cc432.async.js +1 -0
  290. package/static/dist/{8025.7dc65c6a.async.js → 6661.13953d0c.async.js} +1 -1
  291. package/static/dist/667.1018a7d1.async.js +1 -0
  292. package/static/dist/667.1018a7d1.async.js.gz +0 -0
  293. package/static/dist/{9308.3202ac13.async.js → 6674.3f6cbfb7.async.js} +1 -1
  294. package/static/dist/6674.3f6cbfb7.async.js.gz +0 -0
  295. package/static/dist/{3714.8d6dba9e.async.js → 672.09e440db.async.js} +1 -1
  296. package/static/dist/672.09e440db.async.js.gz +0 -0
  297. package/static/dist/{8315.3c15bde0.async.js → 6773.f0165234.async.js} +1 -1
  298. package/static/dist/6956.954dcb7f.async.js +1 -0
  299. package/static/dist/6956.954dcb7f.async.js.gz +0 -0
  300. package/static/dist/6991.000de5eb.async.js +1 -0
  301. package/static/dist/6991.000de5eb.async.js.gz +0 -0
  302. package/static/dist/6999.333d97b6.async.js +1 -0
  303. package/static/dist/7045.45a9b0c4.async.js +1 -0
  304. package/static/dist/7045.45a9b0c4.async.js.gz +0 -0
  305. package/static/dist/7112.45d46596.async.js +1 -0
  306. package/static/dist/7112.45d46596.async.js.gz +0 -0
  307. package/static/dist/7158.f154d91b.async.js +1 -0
  308. package/static/dist/7171.8fba4715.async.js +1 -0
  309. package/static/dist/7171.8fba4715.async.js.gz +0 -0
  310. package/static/dist/{7993.ed86bf44.async.js → 7205.b5ce4f28.async.js} +1 -1
  311. package/static/dist/{5662.678b0cfb.async.js → 7247.28497f87.async.js} +1 -1
  312. package/static/dist/7247.28497f87.async.js.gz +0 -0
  313. package/static/dist/7329.4451ada2.async.js +1 -0
  314. package/static/dist/743.f9b3f021.async.js +1 -0
  315. package/static/dist/7468.f78fdcfa.async.js +1 -0
  316. package/static/dist/7468.f78fdcfa.async.js.gz +0 -0
  317. package/static/dist/7508.11799658.async.js +1 -0
  318. package/static/dist/7508.11799658.async.js.gz +0 -0
  319. package/static/dist/{2635.d4c59d23.async.js → 7559.eed2c5b6.async.js} +1 -1
  320. package/static/dist/7559.eed2c5b6.async.js.gz +0 -0
  321. package/static/dist/7573.6892e238.async.js +1 -0
  322. package/static/dist/7607.ac9cb836.async.js +1 -0
  323. package/static/dist/7607.ac9cb836.async.js.gz +0 -0
  324. package/static/dist/{2958.1a7daa3c.async.js → 7653.f22931b8.async.js} +1 -1
  325. package/static/dist/7681.cffb8dab.async.js +1 -0
  326. package/static/dist/7681.cffb8dab.async.js.gz +0 -0
  327. package/static/dist/{9974.c867bc89.async.js → 7701.fac6a316.async.js} +1 -1
  328. package/static/dist/7728.500760a1.async.js +1 -0
  329. package/static/dist/7728.500760a1.async.js.gz +0 -0
  330. package/static/dist/7783.d4562c70.async.js +1 -0
  331. package/static/dist/7783.d4562c70.async.js.gz +0 -0
  332. package/static/dist/{6431.c50479be.async.js → 7797.c5a79206.async.js} +1 -1
  333. package/static/dist/7845.fda583de.async.js +1 -0
  334. package/static/dist/7857.dbe75770.async.js +1 -0
  335. package/static/dist/7857.dbe75770.async.js.gz +0 -0
  336. package/static/dist/7869.2a318fd5.async.js +1 -0
  337. package/static/dist/7889.ba30e2bc.async.js +1 -0
  338. package/static/dist/7889.ba30e2bc.async.js.gz +0 -0
  339. package/static/dist/7901.7726d37e.async.js +1 -0
  340. package/static/dist/7907.b2699834.async.js +1 -0
  341. package/static/dist/{8878.8367da80.async.js → 7913.2f69ee1c.async.js} +1 -1
  342. package/static/dist/{6598.01b8b308.async.js → 8095.baec2da2.async.js} +1 -1
  343. package/static/dist/8111.d0c7a451.async.js +1 -0
  344. package/static/dist/8111.d0c7a451.async.js.gz +0 -0
  345. package/static/dist/8165.ff0c01a7.async.js +1 -0
  346. package/static/dist/{5580.48b4722f.async.js → 8357.907fff49.async.js} +1 -1
  347. package/static/dist/842.63fc6c73.async.js +1 -0
  348. package/static/dist/842.63fc6c73.async.js.gz +0 -0
  349. package/static/dist/8504.9cc2ad4b.async.js +1 -0
  350. package/static/dist/8504.9cc2ad4b.async.js.gz +0 -0
  351. package/static/dist/8516.636f0e95.async.js +1 -0
  352. package/static/dist/8516.636f0e95.async.js.gz +0 -0
  353. package/static/dist/8644.e25c61fa.async.js +1 -0
  354. package/static/dist/8644.e25c61fa.async.js.gz +0 -0
  355. package/static/dist/8703.1b747c44.async.js +1 -0
  356. package/static/dist/8703.1b747c44.async.js.gz +0 -0
  357. package/static/dist/8867.d6253060.async.js +1 -0
  358. package/static/dist/{5436.f2e37c36.async.js → 8893.8ead5819.async.js} +1 -1
  359. package/static/dist/{6437.91ff515b.async.js → 8917.9c54ed03.async.js} +1 -1
  360. package/static/dist/892.47158183.async.js +1 -0
  361. package/static/dist/892.47158183.async.js.gz +0 -0
  362. package/static/dist/9015.5b231e77.async.js +1 -0
  363. package/static/dist/9020.3a396f11.async.js +1 -0
  364. package/static/dist/9020.3a396f11.async.js.gz +0 -0
  365. package/static/dist/{6711.84451b08.async.js → 9081.437dcaea.async.js} +1 -1
  366. package/static/dist/{7647.e9446154.async.js → 9185.7591ccab.async.js} +1 -1
  367. package/static/dist/9211.c58d5083.async.js +1 -0
  368. package/static/dist/9211.c58d5083.async.js.gz +0 -0
  369. package/static/dist/{7036.fdeb74d0.async.js → 9219.c5962724.async.js} +1 -1
  370. package/static/dist/{1571.94ddca13.async.js → 9380.df4bce3e.async.js} +1 -1
  371. package/static/dist/9380.df4bce3e.async.js.gz +0 -0
  372. package/static/dist/9384.e0c1d949.async.js +1 -0
  373. package/static/dist/9384.e0c1d949.async.js.gz +0 -0
  374. package/static/dist/{8080.056470f6.async.js → 9445.3647dcaa.async.js} +1 -1
  375. package/static/dist/951.3aac61ca.async.js +1 -0
  376. package/static/dist/9541.8e2bab43.async.js +1 -0
  377. package/static/dist/9541.8e2bab43.async.js.gz +0 -0
  378. package/static/dist/9621.3a1a2777.async.js +1 -0
  379. package/static/dist/9645.d470c417.async.js +1 -0
  380. package/static/dist/9753.f947eb7b.async.js +1 -0
  381. package/static/dist/9816.1e9930f6.async.js +1 -0
  382. package/static/dist/9816.1e9930f6.async.js.gz +0 -0
  383. package/static/dist/{8682.597beedb.async.js → 9829.e4ba1956.async.js} +1 -1
  384. package/static/dist/{2905.a8f810e1.async.js → 9979.5f051cb4.async.js} +1 -1
  385. package/static/dist/index.html +3 -3
  386. package/static/dist/layouts__index.1f483079.async.js +1 -0
  387. package/static/dist/layouts__index.1f483079.async.js.gz +0 -0
  388. package/static/dist/layouts__index.32b9042a.chunk.css +1 -0
  389. package/static/dist/layouts__index.32b9042a.chunk.css.gz +0 -0
  390. package/static/dist/preload_helper.aed13b44.js +1 -0
  391. package/static/dist/{src__pages__404.3fd8332e.async.js → src__pages__404.c72d5253.async.js} +1 -1
  392. package/static/dist/src__pages__config__index.acb8e7a8.async.js +1 -0
  393. package/static/dist/src__pages__config__index.acb8e7a8.async.js.gz +0 -0
  394. package/static/dist/{src__pages__crontab__const.aba07deb.async.js → src__pages__crontab__const.3b7b55ae.async.js} +1 -1
  395. package/static/dist/src__pages__crontab__dailyResults.746e53f8.async.js +1 -0
  396. package/static/dist/src__pages__crontab__detail.a33259f9.async.js +1 -0
  397. package/static/dist/src__pages__crontab__detail.a33259f9.async.js.gz +0 -0
  398. package/static/dist/{src__pages__crontab__index.5bbea517.chunk.css → src__pages__crontab__index.9f12d3bf.chunk.css} +1 -1
  399. package/static/dist/src__pages__crontab__index.c3c551ca.async.js +1 -0
  400. package/static/dist/src__pages__crontab__index.c3c551ca.async.js.gz +0 -0
  401. package/static/dist/src__pages__crontab__instanceHistory.52c7b4b0.async.js +1 -0
  402. package/static/dist/src__pages__crontab__instanceHistory.52c7b4b0.async.js.gz +0 -0
  403. package/static/dist/src__pages__crontab__logModal.c95ea819.async.js +1 -0
  404. package/static/dist/src__pages__crontab__logModal.c95ea819.async.js.gz +0 -0
  405. package/static/dist/src__pages__crontab__modal.245ba7a7.async.js +1 -0
  406. package/static/dist/src__pages__crontab__modal.245ba7a7.async.js.gz +0 -0
  407. package/static/dist/src__pages__crontab__stopRequest.6a8d77ea.async.js +1 -0
  408. package/static/dist/src__pages__crontab__triggerList.33437e6a.async.js +1 -0
  409. package/static/dist/src__pages__crontab__triggerList.33437e6a.async.js.gz +0 -0
  410. package/static/dist/src__pages__crontab__triggerTiming.38d328c7.async.js +1 -0
  411. package/static/dist/src__pages__crontab__triggerTiming.38d328c7.async.js.gz +0 -0
  412. package/static/dist/src__pages__crontab__triggerUpdates.e1ddc531.async.js +1 -0
  413. package/static/dist/{src__pages__crontab__type.d7af36e5.async.js → src__pages__crontab__type.19dd8dd9.async.js} +1 -1
  414. package/static/dist/src__pages__crontab__viewCreateModal.ef74528f.async.js +1 -0
  415. package/static/dist/src__pages__crontab__viewCreateModal.ef74528f.async.js.gz +0 -0
  416. package/static/dist/src__pages__crontab__viewManageModal.8cc7f6c6.async.js +1 -0
  417. package/static/dist/src__pages__crontab__viewManageModal.8cc7f6c6.async.js.gz +0 -0
  418. package/static/dist/src__pages__dashboard__index.4f6a65e5.async.js +1 -0
  419. package/static/dist/src__pages__dashboard__index.4f6a65e5.async.js.gz +0 -0
  420. package/static/dist/src__pages__dashboard__index.de756a4f.chunk.css +1 -0
  421. package/static/dist/src__pages__dashboard__taskResultModal.971b6793.async.js +1 -0
  422. package/static/dist/src__pages__dashboard__timingStatistic.8edabcf4.async.js +1 -0
  423. package/static/dist/src__pages__dependence__index.ff16abd8.async.js +1 -0
  424. package/static/dist/src__pages__dependence__index.ff16abd8.async.js.gz +0 -0
  425. package/static/dist/src__pages__dependence__logModal.306e7477.async.js +1 -0
  426. package/static/dist/src__pages__dependence__logModal.306e7477.async.js.gz +0 -0
  427. package/static/dist/src__pages__dependence__modal.2e575a7d.async.js +1 -0
  428. package/static/dist/src__pages__dependence__modal.2e575a7d.async.js.gz +0 -0
  429. package/static/dist/{src__pages__dependence__type.e48c5c88.async.js → src__pages__dependence__type.20aded90.async.js} +1 -1
  430. package/static/dist/src__pages__diff__index.7e1f8cd9.async.js +1 -0
  431. package/static/dist/src__pages__diff__index.7e1f8cd9.async.js.gz +0 -0
  432. package/static/dist/src__pages__env__editNameModal.74e8a956.async.js +1 -0
  433. package/static/dist/src__pages__env__index.8e3c5a16.async.js +1 -0
  434. package/static/dist/src__pages__env__index.8e3c5a16.async.js.gz +0 -0
  435. package/static/dist/src__pages__env__modal.58e12beb.async.js +1 -0
  436. package/static/dist/src__pages__env__modal.58e12beb.async.js.gz +0 -0
  437. package/static/dist/src__pages__error__index.f943122d.async.js +1 -0
  438. package/static/dist/src__pages__initialization__index.163202cc.chunk.css +1 -0
  439. package/static/dist/src__pages__initialization__index.fa306f0a.async.js +1 -0
  440. package/static/dist/src__pages__initialization__index.fa306f0a.async.js.gz +0 -0
  441. package/static/dist/src__pages__log__index.c209ed9b.chunk.css +1 -0
  442. package/static/dist/src__pages__log__index.fc1b1063.async.js +1 -0
  443. package/static/dist/src__pages__log__index.fc1b1063.async.js.gz +0 -0
  444. package/static/dist/src__pages__login__index.65d17582.chunk.css +1 -0
  445. package/static/dist/src__pages__login__index.f8e99429.async.js +1 -0
  446. package/static/dist/src__pages__login__index.f8e99429.async.js.gz +0 -0
  447. package/static/dist/src__pages__script__components__UnsupportedFilePreview__index.de7e61ca.async.js +1 -0
  448. package/static/dist/src__pages__script__components__UnsupportedFilePreview__index.de7e61ca.async.js.gz +0 -0
  449. package/static/dist/src__pages__script__editModal.030adb78.async.js +1 -0
  450. package/static/dist/src__pages__script__editModal.030adb78.async.js.gz +0 -0
  451. package/static/dist/src__pages__script__editModal.0557fafc.chunk.css +1 -0
  452. package/static/dist/src__pages__script__editNameModal.0557fafc.chunk.css +1 -0
  453. package/static/dist/src__pages__script__editNameModal.4e4fad4a.async.js +1 -0
  454. package/static/dist/src__pages__script__editNameModal.4e4fad4a.async.js.gz +0 -0
  455. package/static/dist/{src__pages__script__historyDrawer.a449193a.chunk.css → src__pages__script__historyDrawer.0ab71b73.chunk.css} +1 -1
  456. package/static/dist/src__pages__script__historyDrawer.a6420226.async.js +1 -0
  457. package/static/dist/src__pages__script__historyDrawer.a6420226.async.js.gz +0 -0
  458. package/static/dist/src__pages__script__index.d4564ccf.chunk.css +1 -0
  459. package/static/dist/src__pages__script__index.f8d1b03e.async.js +1 -0
  460. package/static/dist/src__pages__script__index.f8d1b03e.async.js.gz +0 -0
  461. package/static/dist/src__pages__script__renameModal.640c223b.async.js +1 -0
  462. package/static/dist/src__pages__script__saveModal.2e5a1cda.async.js +1 -0
  463. package/static/dist/{src__pages__script__saveWithHistory.99ece830.async.js → src__pages__script__saveWithHistory.6e81e493.async.js} +1 -1
  464. package/static/dist/src__pages__script__setting.9b1efd4f.async.js +1 -0
  465. package/static/dist/src__pages__setting__about.96833c94.async.js +1 -0
  466. package/static/dist/src__pages__setting__about.96833c94.async.js.gz +0 -0
  467. package/static/dist/src__pages__setting__appModal.d52d8964.async.js +1 -0
  468. package/static/dist/src__pages__setting__checkUpdate.535b3f37.async.js +1 -0
  469. package/static/dist/src__pages__setting__checkUpdate.535b3f37.async.js.gz +0 -0
  470. package/static/dist/src__pages__setting__clientIp.bdec4d8d.async.js +1 -0
  471. package/static/dist/src__pages__setting__clientIp.bdec4d8d.async.js.gz +0 -0
  472. package/static/dist/src__pages__setting__dependence.5f2591d8.async.js +1 -0
  473. package/static/dist/src__pages__setting__dependence.5f2591d8.async.js.gz +0 -0
  474. package/static/dist/src__pages__setting__index.ef633884.async.js +1 -0
  475. package/static/dist/src__pages__setting__index.ef633884.async.js.gz +0 -0
  476. package/static/dist/src__pages__setting__loginLog.16ba8e6b.async.js +1 -0
  477. package/static/dist/src__pages__setting__loginLog.16ba8e6b.async.js.gz +0 -0
  478. package/static/dist/src__pages__setting__notification.f53f8d1e.async.js +1 -0
  479. package/static/dist/src__pages__setting__notifyLog.521431ce.async.js +1 -0
  480. package/static/dist/src__pages__setting__notifyLog.521431ce.async.js.gz +0 -0
  481. package/static/dist/src__pages__setting__other.e0a48d72.async.js +1 -0
  482. package/static/dist/src__pages__setting__other.e0a48d72.async.js.gz +0 -0
  483. package/static/dist/src__pages__setting__progress.354d7a2f.async.js +1 -0
  484. package/static/dist/src__pages__setting__security.2e8fd144.async.js +1 -0
  485. package/static/dist/src__pages__setting__security.2e8fd144.async.js.gz +0 -0
  486. package/static/dist/src__pages__setting__systemLog.7b116796.async.js +1 -0
  487. package/static/dist/src__pages__setting__systemLog.7b116796.async.js.gz +0 -0
  488. package/static/dist/src__pages__subscription__index.03e373fc.async.js +1 -0
  489. package/static/dist/src__pages__subscription__index.03e373fc.async.js.gz +0 -0
  490. package/static/dist/src__pages__subscription__logModal.903b015e.async.js +1 -0
  491. package/static/dist/src__pages__subscription__logModal.903b015e.async.js.gz +0 -0
  492. package/static/dist/src__pages__subscription__modal.6dec80af.async.js +1 -0
  493. package/static/dist/umi.70238455.css +1 -0
  494. package/static/dist/umi.70238455.css.gz +0 -0
  495. package/static/dist/umi.e0bcb75b.js +1 -0
  496. package/static/dist/umi.e0bcb75b.js.gz +0 -0
  497. package/version.yaml +7 -11
  498. package/static/dist/1089.0ecc5383.async.js +0 -1
  499. package/static/dist/1089.0ecc5383.async.js.gz +0 -0
  500. package/static/dist/1134.b851963c.async.js +0 -1
  501. package/static/dist/1174.41a43fee.async.js +0 -1
  502. package/static/dist/1174.41a43fee.async.js.gz +0 -0
  503. package/static/dist/119.89e2d610.async.js +0 -1
  504. package/static/dist/119.89e2d610.async.js.gz +0 -0
  505. package/static/dist/1192.4e5740f2.async.js +0 -1
  506. package/static/dist/1212.f87fd07a.async.js.gz +0 -0
  507. package/static/dist/1214.c6469b53.async.js +0 -1
  508. package/static/dist/1352.96a77e1d.async.js +0 -1
  509. package/static/dist/1352.96a77e1d.async.js.gz +0 -0
  510. package/static/dist/1379.f91563a1.async.js +0 -1
  511. package/static/dist/1379.f91563a1.async.js.gz +0 -0
  512. package/static/dist/1571.94ddca13.async.js.gz +0 -0
  513. package/static/dist/1706.ac98cb3f.async.js +0 -1
  514. package/static/dist/1706.ac98cb3f.async.js.gz +0 -0
  515. package/static/dist/1765.5ac01a93.async.js +0 -1
  516. package/static/dist/1765.5ac01a93.async.js.gz +0 -0
  517. package/static/dist/1836.f0b74cf1.async.js +0 -1
  518. package/static/dist/1836.f0b74cf1.async.js.gz +0 -0
  519. package/static/dist/1885.b8f427bf.async.js +0 -1
  520. package/static/dist/1885.b8f427bf.async.js.gz +0 -0
  521. package/static/dist/1887.9e0d3da8.async.js +0 -1
  522. package/static/dist/1887.9e0d3da8.async.js.gz +0 -0
  523. package/static/dist/1967.3f3945d0.async.js +0 -1
  524. package/static/dist/1967.3f3945d0.async.js.gz +0 -0
  525. package/static/dist/198.db47fc1a.async.js +0 -1
  526. package/static/dist/198.db47fc1a.async.js.gz +0 -0
  527. package/static/dist/2003.8eafeca8.async.js +0 -1
  528. package/static/dist/2031.6af40025.async.js +0 -1
  529. package/static/dist/2231.29b754cf.async.js +0 -1
  530. package/static/dist/2325.dfa32834.async.js +0 -1
  531. package/static/dist/2325.dfa32834.async.js.gz +0 -0
  532. package/static/dist/2336.0756f45f.async.js +0 -1
  533. package/static/dist/2338.d678967d.async.js +0 -1
  534. package/static/dist/2338.d678967d.async.js.gz +0 -0
  535. package/static/dist/2372.b5a50ee7.async.js +0 -1
  536. package/static/dist/2372.b5a50ee7.async.js.gz +0 -0
  537. package/static/dist/2476.4e9b0992.async.js +0 -1
  538. package/static/dist/2476.4e9b0992.async.js.gz +0 -0
  539. package/static/dist/2537.2b262ee0.async.js +0 -1
  540. package/static/dist/2537.2b262ee0.async.js.gz +0 -0
  541. package/static/dist/2577.aa8fe709.async.js +0 -1
  542. package/static/dist/2577.aa8fe709.async.js.gz +0 -0
  543. package/static/dist/2635.d4c59d23.async.js.gz +0 -0
  544. package/static/dist/2636.70ece391.async.js +0 -1
  545. package/static/dist/2664.e69530fb.async.js +0 -1
  546. package/static/dist/2664.e69530fb.async.js.gz +0 -0
  547. package/static/dist/2693.51c2636b.async.js +0 -1
  548. package/static/dist/2693.51c2636b.async.js.gz +0 -0
  549. package/static/dist/2750.7aa38add.async.js +0 -1
  550. package/static/dist/2808.cdc0995c.async.js +0 -1
  551. package/static/dist/2808.cdc0995c.async.js.gz +0 -0
  552. package/static/dist/2821.651f31e5.async.js +0 -1
  553. package/static/dist/2821.651f31e5.async.js.gz +0 -0
  554. package/static/dist/2890.add55e85.async.js +0 -1
  555. package/static/dist/2890.add55e85.async.js.gz +0 -0
  556. package/static/dist/2901.6d0de54e.async.js +0 -1
  557. package/static/dist/2901.6d0de54e.async.js.gz +0 -0
  558. package/static/dist/292.27ce781f.async.js +0 -1
  559. package/static/dist/292.27ce781f.async.js.gz +0 -0
  560. package/static/dist/293.80d14a4f.async.js +0 -1
  561. package/static/dist/2986.4c49eef7.async.js +0 -1
  562. package/static/dist/300.08ac9875.async.js +0 -1
  563. package/static/dist/300.08ac9875.async.js.gz +0 -0
  564. package/static/dist/3055.a99f8e4c.async.js +0 -1
  565. package/static/dist/3191.3b7e4b42.async.js +0 -1
  566. package/static/dist/3191.3b7e4b42.async.js.gz +0 -0
  567. package/static/dist/3382.a584a111.async.js +0 -1
  568. package/static/dist/3382.a584a111.async.js.gz +0 -0
  569. package/static/dist/3383.041eee73.async.js +0 -1
  570. package/static/dist/3383.041eee73.async.js.gz +0 -0
  571. package/static/dist/3390.fb4b6851.async.js +0 -1
  572. package/static/dist/3481.333c2962.async.js +0 -1
  573. package/static/dist/3512.95e41255.async.js +0 -1
  574. package/static/dist/3512.95e41255.async.js.gz +0 -0
  575. package/static/dist/3714.8d6dba9e.async.js.gz +0 -0
  576. package/static/dist/3840.801ded2b.async.js +0 -1
  577. package/static/dist/3906.a5eee612.async.js +0 -1
  578. package/static/dist/3906.a5eee612.async.js.gz +0 -0
  579. package/static/dist/3948.4fe809fd.async.js +0 -1
  580. package/static/dist/3948.4fe809fd.async.js.gz +0 -0
  581. package/static/dist/4324.5a5887d1.async.js +0 -1
  582. package/static/dist/4324.5a5887d1.async.js.gz +0 -0
  583. package/static/dist/4559.faab3673.async.js +0 -1
  584. package/static/dist/4559.faab3673.async.js.gz +0 -0
  585. package/static/dist/4573.16f19278.async.js +0 -1
  586. package/static/dist/4573.16f19278.async.js.gz +0 -0
  587. package/static/dist/4736.7c4c489b.async.js +0 -1
  588. package/static/dist/4736.7c4c489b.async.js.gz +0 -0
  589. package/static/dist/4818.c83facd7.async.js +0 -1
  590. package/static/dist/4887.8e3ae573.async.js +0 -1
  591. package/static/dist/4887.8e3ae573.async.js.gz +0 -0
  592. package/static/dist/4934.f3539d08.async.js +0 -1
  593. package/static/dist/4934.f3539d08.async.js.gz +0 -0
  594. package/static/dist/5.3ebdd181.async.js +0 -1
  595. package/static/dist/5077.cbd111cd.async.js +0 -1
  596. package/static/dist/5077.cbd111cd.async.js.gz +0 -0
  597. package/static/dist/5157.7c5af144.async.js +0 -1
  598. package/static/dist/540.19ddf020.async.js +0 -1
  599. package/static/dist/5481.e2945a63.async.js +0 -1
  600. package/static/dist/5481.e2945a63.async.js.gz +0 -0
  601. package/static/dist/5662.678b0cfb.async.js.gz +0 -0
  602. package/static/dist/5970.5862e59e.async.js +0 -1
  603. package/static/dist/5970.5862e59e.async.js.gz +0 -0
  604. package/static/dist/6013.db535339.async.js +0 -1
  605. package/static/dist/6013.db535339.async.js.gz +0 -0
  606. package/static/dist/6016.1e6574b6.async.js +0 -1
  607. package/static/dist/6035.32ebfad9.async.js +0 -1
  608. package/static/dist/6035.32ebfad9.async.js.gz +0 -0
  609. package/static/dist/6212.30a9c190.async.js +0 -1
  610. package/static/dist/6212.30a9c190.async.js.gz +0 -0
  611. package/static/dist/6341.673fb65c.async.js +0 -1
  612. package/static/dist/6341.673fb65c.async.js.gz +0 -0
  613. package/static/dist/6367.8b0e838c.async.js +0 -1
  614. package/static/dist/6367.8b0e838c.async.js.gz +0 -0
  615. package/static/dist/6569.55177f6a.async.js +0 -1
  616. package/static/dist/6569.55177f6a.async.js.gz +0 -0
  617. package/static/dist/6610.c111af7e.async.js +0 -1
  618. package/static/dist/6610.c111af7e.async.js.gz +0 -0
  619. package/static/dist/6638.87a163d2.async.js.gz +0 -0
  620. package/static/dist/6646.95e92533.async.js +0 -1
  621. package/static/dist/6646.95e92533.async.js.gz +0 -0
  622. package/static/dist/6665.1d099ad1.async.js +0 -1
  623. package/static/dist/685.2419bacf.async.js +0 -1
  624. package/static/dist/6872.fcc9ce17.async.js +0 -1
  625. package/static/dist/6872.fcc9ce17.async.js.gz +0 -0
  626. package/static/dist/691.187a388c.async.js +0 -1
  627. package/static/dist/691.187a388c.async.js.gz +0 -0
  628. package/static/dist/7146.4dc150b1.async.js +0 -1
  629. package/static/dist/7146.4dc150b1.async.js.gz +0 -0
  630. package/static/dist/7231.f7e5b668.async.js +0 -1
  631. package/static/dist/7231.f7e5b668.async.js.gz +0 -0
  632. package/static/dist/7253.4b9bf133.async.js +0 -1
  633. package/static/dist/7253.4b9bf133.async.js.gz +0 -0
  634. package/static/dist/7278.96bf439f.async.js +0 -1
  635. package/static/dist/7278.96bf439f.async.js.gz +0 -0
  636. package/static/dist/7285.d561cf26.async.js +0 -1
  637. package/static/dist/7355.fca746f5.async.js +0 -1
  638. package/static/dist/7355.fca746f5.async.js.gz +0 -0
  639. package/static/dist/7384.1bb449d5.async.js +0 -1
  640. package/static/dist/7384.1bb449d5.async.js.gz +0 -0
  641. package/static/dist/7441.ee1bf2bb.async.js +0 -1
  642. package/static/dist/7508.3fffed15.chunk.css +0 -1
  643. package/static/dist/7508.3fffed15.chunk.css.gz +0 -0
  644. package/static/dist/7508.d90eac63.async.js +0 -1
  645. package/static/dist/7508.d90eac63.async.js.gz +0 -0
  646. package/static/dist/752.66fdc531.async.js +0 -1
  647. package/static/dist/7714.1e826854.async.js +0 -1
  648. package/static/dist/7802.34255805.async.js +0 -1
  649. package/static/dist/7802.34255805.async.js.gz +0 -0
  650. package/static/dist/7984.eaac7402.async.js +0 -1
  651. package/static/dist/7984.eaac7402.async.js.gz +0 -0
  652. package/static/dist/8033.5cb31493.async.js +0 -1
  653. package/static/dist/8033.5cb31493.async.js.gz +0 -0
  654. package/static/dist/8078.8586c875.async.js +0 -1
  655. package/static/dist/8078.8586c875.async.js.gz +0 -0
  656. package/static/dist/8142.a074ddf1.async.js +0 -1
  657. package/static/dist/8147.2fb55202.async.js +0 -1
  658. package/static/dist/8147.2fb55202.async.js.gz +0 -0
  659. package/static/dist/8187.48c130d6.async.js +0 -1
  660. package/static/dist/8187.48c130d6.async.js.gz +0 -0
  661. package/static/dist/831.9756b44d.async.js +0 -1
  662. package/static/dist/8495.d53e15ca.async.js +0 -1
  663. package/static/dist/8495.d53e15ca.async.js.gz +0 -0
  664. package/static/dist/8587.315b06c0.async.js +0 -1
  665. package/static/dist/8776.e8798a5a.async.js +0 -1
  666. package/static/dist/8779.3e755010.async.js +0 -1
  667. package/static/dist/8844.a0fef08e.async.js +0 -1
  668. package/static/dist/8844.a0fef08e.async.js.gz +0 -0
  669. package/static/dist/8865.ed665d31.async.js +0 -1
  670. package/static/dist/901.7ee5c6d3.async.js +0 -1
  671. package/static/dist/9033.f2e29d04.async.js +0 -1
  672. package/static/dist/9095.816eeb1a.async.js +0 -1
  673. package/static/dist/9271.231db2ce.async.js +0 -1
  674. package/static/dist/9308.3202ac13.async.js.gz +0 -0
  675. package/static/dist/9323.a33f47da.async.js +0 -1
  676. package/static/dist/9323.a33f47da.async.js.gz +0 -0
  677. package/static/dist/965.8d9b1fbd.async.js +0 -1
  678. package/static/dist/965.8d9b1fbd.async.js.gz +0 -0
  679. package/static/dist/9730.801665a3.async.js +0 -1
  680. package/static/dist/9761.360a19d8.async.js +0 -1
  681. package/static/dist/9761.360a19d8.async.js.gz +0 -0
  682. package/static/dist/layouts__index.86b6bcbe.chunk.css +0 -1
  683. package/static/dist/layouts__index.86b6bcbe.chunk.css.gz +0 -0
  684. package/static/dist/layouts__index.c8e9788e.async.js +0 -1
  685. package/static/dist/layouts__index.c8e9788e.async.js.gz +0 -0
  686. package/static/dist/preload_helper.8b8f6581.js +0 -1
  687. package/static/dist/src__pages__config__index.d18d8f95.async.js +0 -1
  688. package/static/dist/src__pages__crontab__detail.88729e8f.async.js +0 -1
  689. package/static/dist/src__pages__crontab__detail.88729e8f.async.js.gz +0 -0
  690. package/static/dist/src__pages__crontab__index.8aa9d297.async.js +0 -1
  691. package/static/dist/src__pages__crontab__index.8aa9d297.async.js.gz +0 -0
  692. package/static/dist/src__pages__crontab__logModal.930535e2.async.js +0 -1
  693. package/static/dist/src__pages__crontab__logModal.930535e2.async.js.gz +0 -0
  694. package/static/dist/src__pages__crontab__modal.a2c8fdcc.async.js +0 -1
  695. package/static/dist/src__pages__crontab__modal.a2c8fdcc.async.js.gz +0 -0
  696. package/static/dist/src__pages__crontab__viewCreateModal.7b4f9cbe.async.js +0 -1
  697. package/static/dist/src__pages__crontab__viewCreateModal.7b4f9cbe.async.js.gz +0 -0
  698. package/static/dist/src__pages__crontab__viewManageModal.cd454ea0.async.js +0 -1
  699. package/static/dist/src__pages__crontab__viewManageModal.cd454ea0.async.js.gz +0 -0
  700. package/static/dist/src__pages__dashboard__index.c05ce904.async.js +0 -1
  701. package/static/dist/src__pages__dashboard__index.c05ce904.async.js.gz +0 -0
  702. package/static/dist/src__pages__dashboard__taskResultModal.7795d6e1.async.js +0 -1
  703. package/static/dist/src__pages__dependence__index.5b7fd97d.async.js +0 -1
  704. package/static/dist/src__pages__dependence__index.5b7fd97d.async.js.gz +0 -0
  705. package/static/dist/src__pages__dependence__logModal.01729f63.async.js +0 -1
  706. package/static/dist/src__pages__dependence__logModal.01729f63.async.js.gz +0 -0
  707. package/static/dist/src__pages__dependence__modal.ef7ae53b.async.js +0 -1
  708. package/static/dist/src__pages__dependence__modal.ef7ae53b.async.js.gz +0 -0
  709. package/static/dist/src__pages__diff__index.4233ea93.async.js +0 -1
  710. package/static/dist/src__pages__diff__index.4233ea93.async.js.gz +0 -0
  711. package/static/dist/src__pages__env__editNameModal.c13d47d2.async.js +0 -1
  712. package/static/dist/src__pages__env__index.eddb35bf.async.js +0 -1
  713. package/static/dist/src__pages__env__index.eddb35bf.async.js.gz +0 -0
  714. package/static/dist/src__pages__env__modal.4d71adb3.async.js +0 -1
  715. package/static/dist/src__pages__env__modal.4d71adb3.async.js.gz +0 -0
  716. package/static/dist/src__pages__error__index.66605c72.async.js +0 -1
  717. package/static/dist/src__pages__initialization__index.66819338.chunk.css +0 -1
  718. package/static/dist/src__pages__initialization__index.9c1c5b76.async.js +0 -1
  719. package/static/dist/src__pages__initialization__index.9c1c5b76.async.js.gz +0 -0
  720. package/static/dist/src__pages__log__index.71250e0d.async.js +0 -1
  721. package/static/dist/src__pages__log__index.71250e0d.async.js.gz +0 -0
  722. package/static/dist/src__pages__log__index.9f2eae80.chunk.css +0 -1
  723. package/static/dist/src__pages__login__index.58bb4b38.async.js +0 -1
  724. package/static/dist/src__pages__login__index.58bb4b38.async.js.gz +0 -0
  725. package/static/dist/src__pages__login__index.d00b91e8.chunk.css +0 -1
  726. package/static/dist/src__pages__script__components__UnsupportedFilePreview__index.c347a13a.async.js +0 -1
  727. package/static/dist/src__pages__script__components__UnsupportedFilePreview__index.c347a13a.async.js.gz +0 -0
  728. package/static/dist/src__pages__script__editModal.d15f8d78.async.js +0 -1
  729. package/static/dist/src__pages__script__editModal.d15f8d78.async.js.gz +0 -0
  730. package/static/dist/src__pages__script__editNameModal.789ad87b.async.js +0 -1
  731. package/static/dist/src__pages__script__editNameModal.789ad87b.async.js.gz +0 -0
  732. package/static/dist/src__pages__script__historyDrawer.8c58d958.async.js +0 -1
  733. package/static/dist/src__pages__script__historyDrawer.8c58d958.async.js.gz +0 -0
  734. package/static/dist/src__pages__script__index.96a6d30f.async.js +0 -1
  735. package/static/dist/src__pages__script__index.96a6d30f.async.js.gz +0 -0
  736. package/static/dist/src__pages__script__index.ab360776.chunk.css +0 -1
  737. package/static/dist/src__pages__script__renameModal.0ab029e7.async.js +0 -1
  738. package/static/dist/src__pages__script__saveModal.8fca1a22.async.js +0 -1
  739. package/static/dist/src__pages__script__setting.35ad4f02.async.js +0 -1
  740. package/static/dist/src__pages__setting__about.3d3c019f.async.js +0 -1
  741. package/static/dist/src__pages__setting__about.3d3c019f.async.js.gz +0 -0
  742. package/static/dist/src__pages__setting__appModal.7eaeb9d3.async.js +0 -1
  743. package/static/dist/src__pages__setting__checkUpdate.429a42f3.async.js +0 -1
  744. package/static/dist/src__pages__setting__checkUpdate.429a42f3.async.js.gz +0 -0
  745. package/static/dist/src__pages__setting__clientIp.3a8711ed.async.js +0 -1
  746. package/static/dist/src__pages__setting__clientIp.3a8711ed.async.js.gz +0 -0
  747. package/static/dist/src__pages__setting__dependence.c227c0f5.async.js +0 -1
  748. package/static/dist/src__pages__setting__dependence.c227c0f5.async.js.gz +0 -0
  749. package/static/dist/src__pages__setting__index.274ad415.async.js +0 -1
  750. package/static/dist/src__pages__setting__index.274ad415.async.js.gz +0 -0
  751. package/static/dist/src__pages__setting__loginLog.ef135f19.async.js +0 -1
  752. package/static/dist/src__pages__setting__loginLog.ef135f19.async.js.gz +0 -0
  753. package/static/dist/src__pages__setting__notification.2ffe4e5a.async.js +0 -1
  754. package/static/dist/src__pages__setting__notifyLog.5ef5b578.async.js +0 -1
  755. package/static/dist/src__pages__setting__notifyLog.5ef5b578.async.js.gz +0 -0
  756. package/static/dist/src__pages__setting__other.e744c0d1.async.js +0 -1
  757. package/static/dist/src__pages__setting__other.e744c0d1.async.js.gz +0 -0
  758. package/static/dist/src__pages__setting__progress.2ccae3d7.async.js +0 -1
  759. package/static/dist/src__pages__setting__security.e2d71ebb.async.js +0 -1
  760. package/static/dist/src__pages__setting__security.e2d71ebb.async.js.gz +0 -0
  761. package/static/dist/src__pages__setting__systemLog.000bcb5e.async.js +0 -1
  762. package/static/dist/src__pages__setting__systemLog.000bcb5e.async.js.gz +0 -0
  763. package/static/dist/src__pages__subscription__index.f556ae4c.async.js +0 -1
  764. package/static/dist/src__pages__subscription__index.f556ae4c.async.js.gz +0 -0
  765. package/static/dist/src__pages__subscription__logModal.cdba5139.async.js +0 -1
  766. package/static/dist/src__pages__subscription__logModal.cdba5139.async.js.gz +0 -0
  767. package/static/dist/src__pages__subscription__modal.8f04f506.async.js +0 -1
  768. package/static/dist/umi.73936e34.js +0 -1
  769. package/static/dist/umi.73936e34.js.gz +0 -0
  770. package/static/dist/umi.a4d14b92.css +0 -1
  771. package/static/dist/umi.a4d14b92.css.gz +0 -0
  772. /package/static/dist/{1883.675b6a18.chunk.css → 3012.675b6a18.chunk.css} +0 -0
  773. /package/static/dist/{1883.675b6a18.chunk.css.gz → 3012.675b6a18.chunk.css.gz} +0 -0
  774. /package/static/dist/{292.1b962b29.chunk.css → 6049.1b962b29.chunk.css} +0 -0
  775. /package/static/dist/{292.1b962b29.chunk.css.gz → 6049.1b962b29.chunk.css.gz} +0 -0
@@ -0,0 +1,1338 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.triggerHistory = exports.TriggerHistory = exports.installTriggerHistory = exports.slotId = exports.systemOwner = void 0;
7
+ const managedExit_cjs_1 = require("./managedExit.cjs");
8
+ const executionIdentity_1 = require("./executionIdentity");
9
+ const cronProcess_1 = require("./cronProcess");
10
+ var cronProcess_2 = require("./cronProcess");
11
+ Object.defineProperty(exports, "systemOwner", { enumerable: true, get: function () { return cronProcess_2.systemOwner; } });
12
+ const sequelize_1 = require("sequelize");
13
+ const dayjs_1 = __importDefault(require("dayjs"));
14
+ const cronStatistics_1 = require("./cronStatistics");
15
+ const fs_1 = require("fs");
16
+ const path_1 = require("path");
17
+ const crypto_1 = require("crypto");
18
+ const systemScheduleAudit_1 = require("./systemScheduleAudit");
19
+ const scheduleAudit_1 = require("./scheduleAudit");
20
+ function observationKey(id, exit) {
21
+ var _a;
22
+ return { id, outcome: (_a = exit.signal) !== null && _a !== void 0 ? _a : String(exit.code), time: exit.time };
23
+ }
24
+ const historyColumns = `id,cron_id,source,state,queue_context,queue_live_context,dequeued_at,scheduled_at,queued_at,started_at,command_started_at,script_started_at,
25
+ CASE WHEN exit_pending=1 OR (state='unknown' AND reason='restart') THEN NULL ELSE finished_at END AS finished_at,
26
+ CASE WHEN exit_pending=1 THEN CASE WHEN EXISTS (SELECT 1 FROM CronExitObservations
27
+ WHERE trigger_id=CronTriggers.id LIMIT 1 OFFSET 1) OR EXISTS (SELECT 1 FROM CronBoundExitConflicts
28
+ WHERE trigger_id=CronTriggers.id) THEN 'exit_conflict' ELSE 'exit_pending' END ELSE reason END AS reason,
29
+ EXISTS(SELECT 1 FROM CronLegacyExitBookings WHERE trigger_id=CronTriggers.id) AS legacy_exit_booking,
30
+ CASE WHEN exit_pending=1 OR (state='unknown' AND reason='restart') THEN NULL ELSE exit_code END AS exit_code,log_path,observed_at`;
31
+ function slotId(task, ruleIndex, rule, time) {
32
+ return (0, crypto_1.createHash)('sha256')
33
+ .update(JSON.stringify([task, ruleIndex, rule, time]))
34
+ .digest('hex');
35
+ }
36
+ exports.slotId = slotId;
37
+ async function installTriggerHistory(database, transaction) {
38
+ const conflictTable = `CREATE TABLE IF NOT EXISTS CronBoundExitConflicts (
39
+ trigger_id TEXT NOT NULL, outcome TEXT NOT NULL, finished_at INTEGER NOT NULL,
40
+ PRIMARY KEY(trigger_id,outcome,finished_at)) WITHOUT ROWID`;
41
+ const statements = [
42
+ `CREATE TABLE IF NOT EXISTS CronPlanSwitches (seq INTEGER PRIMARY KEY, token TEXT UNIQUE NOT NULL,
43
+ staged_at INTEGER NOT NULL, first_at INTEGER, last_at INTEGER)`,
44
+ 'CREATE TABLE IF NOT EXISTS CronPlanCoverage (id INTEGER PRIMARY KEY CHECK(id=1), since INTEGER NOT NULL)',
45
+ `CREATE TABLE IF NOT EXISTS CronPlanRules (
46
+ cron_id TEXT NOT NULL, rule_index INTEGER NOT NULL, schedule TEXT NOT NULL, zone TEXT NOT NULL,
47
+ since INTEGER NOT NULL, until INTEGER)`,
48
+ 'CREATE UNIQUE INDEX IF NOT EXISTS cron_plan_active ON CronPlanRules(cron_id,rule_index) WHERE until IS NULL',
49
+ `CREATE TABLE IF NOT EXISTS CronTriggers (
50
+ id TEXT PRIMARY KEY, cron_id INTEGER NOT NULL, source TEXT NOT NULL, state TEXT NOT NULL,
51
+ scheduled_at INTEGER, queued_at INTEGER, started_at INTEGER, finished_at INTEGER,
52
+ reason TEXT, exit_code INTEGER, log_path TEXT, counted INTEGER NOT NULL DEFAULT 0,
53
+ owner TEXT, observed_at INTEGER NOT NULL)`,
54
+ `CREATE TABLE IF NOT EXISTS CronShellBindings (
55
+ receipt TEXT PRIMARY KEY, trigger_id TEXT NOT NULL REFERENCES CronTriggers(id) ON DELETE CASCADE)`,
56
+ 'CREATE INDEX IF NOT EXISTS cron_shell_binding_trigger ON CronShellBindings(trigger_id)',
57
+ `CREATE TABLE IF NOT EXISTS CronExitObservations (
58
+ trigger_id TEXT NOT NULL REFERENCES CronTriggers(id) ON DELETE CASCADE,
59
+ outcome TEXT NOT NULL, finished_at INTEGER NOT NULL,
60
+ PRIMARY KEY(trigger_id,outcome,finished_at)) WITHOUT ROWID`,
61
+ `CREATE TABLE IF NOT EXISTS CronLegacyExitBookings (
62
+ trigger_id TEXT PRIMARY KEY, cron_id INTEGER NOT NULL, source TEXT NOT NULL, started_at INTEGER NOT NULL,
63
+ finished_at INTEGER NOT NULL, outcome TEXT NOT NULL, day TEXT NOT NULL, stopped INTEGER NOT NULL DEFAULT 0,
64
+ stat_id INTEGER REFERENCES CrontabStats(id) ON DELETE SET NULL, disputed INTEGER NOT NULL DEFAULT 0)`,
65
+ `CREATE TABLE IF NOT EXISTS CronPrunedUnknownRuns (
66
+ trigger_id TEXT PRIMARY KEY, cron_id INTEGER NOT NULL REFERENCES Crontabs(id) ON DELETE CASCADE,
67
+ source TEXT NOT NULL, started_at INTEGER NOT NULL, last_possible_day TEXT NOT NULL) WITHOUT ROWID`,
68
+ 'CREATE INDEX IF NOT EXISTS cron_pruned_unknown_day ON CronPrunedUnknownRuns(last_possible_day)',
69
+ `CREATE TABLE IF NOT EXISTS CronSystemPlans (id INTEGER PRIMARY KEY, staged INTEGER NOT NULL, confirmed INTEGER, zone TEXT NOT NULL, rules TEXT NOT NULL)`,
70
+ conflictTable,
71
+ `CREATE TABLE IF NOT EXISTS CronUnmatchedBoundExits (
72
+ trigger_id TEXT PRIMARY KEY, outcome TEXT NOT NULL, finished_at INTEGER NOT NULL) WITHOUT ROWID`,
73
+ 'CREATE INDEX IF NOT EXISTS cron_legacy_booking_stat ON CronLegacyExitBookings(stat_id) WHERE stat_id IS NOT NULL',
74
+ 'CREATE TABLE IF NOT EXISTS CronStatRetention (id INTEGER PRIMARY KEY CHECK(id=1), first_day TEXT NOT NULL)',
75
+ 'CREATE TABLE IF NOT EXISTS CronHistoryRetention (id INTEGER PRIMARY KEY CHECK(id=1), cutoff INTEGER NOT NULL)',
76
+ `CREATE TABLE IF NOT EXISTS CronStopBatches (
77
+ request_id TEXT PRIMARY KEY, cron_ids TEXT NOT NULL, snapshot TEXT)`,
78
+ "CREATE INDEX IF NOT EXISTS cron_stop_batch_pending ON CronStopBatches(request_id) WHERE snapshot IS NOT NULL",
79
+ `CREATE TABLE IF NOT EXISTS CronStopRequests (
80
+ instance_id INTEGER PRIMARY KEY, cron_id INTEGER NOT NULL, pid INTEGER NOT NULL, targets TEXT, signalled INTEGER NOT NULL DEFAULT 0)`,
81
+ 'CREATE INDEX IF NOT EXISTS cron_trigger_recent ON CronTriggers(cron_id, observed_at DESC)',
82
+ "CREATE INDEX IF NOT EXISTS cron_trigger_running_task ON CronTriggers(cron_id) WHERE state='running'",
83
+ "CREATE INDEX IF NOT EXISTS cron_trigger_queued_task ON CronTriggers(cron_id) WHERE state='queued'",
84
+ 'CREATE INDEX IF NOT EXISTS cron_trigger_day ON CronTriggers(observed_at)',
85
+ 'CREATE INDEX IF NOT EXISTS cron_trigger_slot ON CronTriggers(scheduled_at) WHERE scheduled_at IS NOT NULL',
86
+ 'CREATE INDEX IF NOT EXISTS cron_trigger_active ON CronTriggers(source, state) WHERE finished_at IS NULL',
87
+ ];
88
+ for (const sql of statements)
89
+ await database.query(sql, { transaction });
90
+ const planFields = await database.query('PRAGMA table_info(CronPlanRules)', { transaction, type: sequelize_1.QueryTypes.SELECT });
91
+ for (const column of ['opened_by', 'closed_by']) {
92
+ if (!planFields.some(field => field.name === column))
93
+ await database.query(`ALTER TABLE CronPlanRules ADD COLUMN ${column} TEXT`, { transaction });
94
+ }
95
+ const conflictFields = await database.query('PRAGMA table_info(CronBoundExitConflicts)', { transaction, type: sequelize_1.QueryTypes.SELECT });
96
+ if (conflictFields.some(field => field.name === 'other_outcome')) {
97
+ await database.query('ALTER TABLE CronBoundExitConflicts RENAME TO CronBoundExitConflictPairs', { transaction });
98
+ await database.query(conflictTable, { transaction });
99
+ await database.query(`INSERT INTO CronBoundExitConflicts(trigger_id,outcome,finished_at)
100
+ SELECT trigger_id,outcome,finished_at FROM CronBoundExitConflictPairs UNION
101
+ SELECT trigger_id,other_outcome,other_finished_at FROM CronBoundExitConflictPairs`, { transaction });
102
+ await database.query('DROP TABLE CronBoundExitConflictPairs', { transaction });
103
+ }
104
+ const bookingFields = await database.query('PRAGMA table_info(CronLegacyExitBookings)', { transaction, type: sequelize_1.QueryTypes.SELECT });
105
+ if (!bookingFields.some(field => field.name === 'bound'))
106
+ await database.query('ALTER TABLE CronLegacyExitBookings ADD COLUMN bound INTEGER NOT NULL DEFAULT 0', { transaction });
107
+ const batchFields = await database.query('PRAGMA table_info(CronStopBatches)', { transaction, type: sequelize_1.QueryTypes.SELECT });
108
+ if (!batchFields.some(column => column.name === 'status_code'))
109
+ await database.query('ALTER TABLE CronStopBatches ADD COLUMN status_code INTEGER NOT NULL DEFAULT 200', { transaction });
110
+ const stopFields = await database.query('PRAGMA table_info(CronStopRequests)', { transaction, type: sequelize_1.QueryTypes.SELECT });
111
+ if (!stopFields.some(column => column.name === 'signalled_at'))
112
+ await database.query('ALTER TABLE CronStopRequests ADD COLUMN signalled_at INTEGER', { transaction });
113
+ if (!stopFields.some(column => column.name === 'root_identity'))
114
+ await database.query('ALTER TABLE CronStopRequests ADD COLUMN root_identity TEXT', { transaction });
115
+ if (!stopFields.some(column => column.name === 'namespace_owner'))
116
+ await database.query('ALTER TABLE CronStopRequests ADD COLUMN namespace_owner TEXT', { transaction });
117
+ const fields = await database.query('PRAGMA table_info(CronTriggers)', { transaction, type: sequelize_1.QueryTypes.SELECT });
118
+ for (const [column, type] of [['queue_live_context', 'TEXT'], ['dequeued_at', 'INTEGER'], ['system_dispatch_at', 'INTEGER'], ['queue_context', 'TEXT'], ['system_rule', 'TEXT'], ['command_started_at', 'INTEGER'], ['instance_id', 'INTEGER'], ['script_started_at', 'INTEGER'], ['stop_requested', 'INTEGER'], ['process_identity', 'TEXT'], ['command_identity', 'TEXT'], ['stop_exit_at', 'INTEGER'], ['stop_exit_verified', 'INTEGER'], ['exit_pending', 'INTEGER']]) {
119
+ if (!fields.some((field) => field.name === column))
120
+ await database.query(`ALTER TABLE CronTriggers ADD COLUMN ${column} ${type}`, { transaction });
121
+ }
122
+ await database.query(`CREATE TRIGGER IF NOT EXISTS cron_exit_observations_settled AFTER UPDATE OF counted ON CronTriggers
123
+ WHEN OLD.exit_pending=1 AND OLD.counted=0 AND NEW.counted=1 BEGIN
124
+ DELETE FROM CronExitObservations WHERE trigger_id=NEW.id;
125
+ END`, { transaction });
126
+ await database.query("CREATE INDEX IF NOT EXISTS cron_system_dispatch ON CronTriggers(COALESCE(system_dispatch_at,observed_at)) WHERE source='system'", { transaction });
127
+ await database.query('CREATE INDEX IF NOT EXISTS cron_trigger_pending_exit ON CronTriggers(id) WHERE exit_pending=1', { transaction });
128
+ await database.query('CREATE UNIQUE INDEX IF NOT EXISTS cron_trigger_instance ON CronTriggers(instance_id) WHERE instance_id IS NOT NULL', { transaction });
129
+ }
130
+ exports.installTriggerHistory = installTriggerHistory;
131
+ function isBoundPublication(file) {
132
+ return /^\.(pending|published)\./.test((0, path_1.basename)(file)) && !(0, managedExit_cjs_1.isLegacyCapture)(file);
133
+ }
134
+ class TriggerHistory {
135
+ constructor(database) {
136
+ this.database = database;
137
+ }
138
+ // No command or instance exists before the scheduler claims the trigger.
139
+ // A cancelled or already claimed row must keep the outcome recorded by its owner.
140
+ async skipQueued(id, reason, finishedAt) {
141
+ await this.database.query(`UPDATE CronTriggers SET state='skipped', reason=$reason, finished_at=$finishedAt
142
+ WHERE id=$id AND source IN ('node','recovery') AND state='queued' AND started_at IS NULL`, { bind: { id, reason, finishedAt }, type: sequelize_1.QueryTypes.BULKUPDATE });
143
+ }
144
+ async enqueue(id, cronId, source, scheduledAt, now = Date.now(), transaction) {
145
+ // The SQLite driver returns changes on the statement that claimed this slot.
146
+ const changed = await this.database.query(`INSERT INTO CronTriggers(id, cron_id, source, scheduled_at, queued_at, observed_at, owner, state)
147
+ VALUES ($id,$cronId,$source,$scheduledAt,$now,$now,$owner,'queued')
148
+ ON CONFLICT(id) DO UPDATE SET state='queued', reason=NULL, finished_at=NULL,
149
+ queued_at=excluded.queued_at, dequeued_at=NULL, queue_context=NULL, queue_live_context=NULL,
150
+ source=excluded.source, owner=excluded.owner
151
+ WHERE excluded.source='recovery' AND state='skipped' AND reason='restart' AND started_at IS NULL`, {
152
+ bind: {
153
+ id,
154
+ cronId,
155
+ source,
156
+ scheduledAt,
157
+ now,
158
+ owner: process.env.SERVICE_TYPE || 'http',
159
+ },
160
+ transaction,
161
+ type: sequelize_1.QueryTypes.BULKUPDATE,
162
+ });
163
+ return changed === 1;
164
+ }
165
+ // Serialize admission with the receipt so simultaneous timers and recovered
166
+ // workers agree on which scheduled run owns the slot. Edits invalidate old waits.
167
+ async enqueueUnlessPending(id, cronId, source, scheduledAt, now, revision = 0) {
168
+ return this.database.transaction(async (transaction) => {
169
+ if (!await this.enqueue(id, cronId, source, scheduledAt, now, transaction))
170
+ return false;
171
+ await this.recoverSystemOwners(cronId, transaction);
172
+ const pending = await this.database.query(`SELECT 1 FROM CronTriggers WHERE cron_id=$cronId AND id<>$id
173
+ AND source IN ('node','recovery','system')
174
+ AND (state='running' OR (state='queued' AND queued_at >= $revision)) LIMIT 1`, { transaction, bind: { cronId, id, revision }, type: sequelize_1.QueryTypes.SELECT });
175
+ if (!pending.length)
176
+ return true;
177
+ await this.finish(id, 'skipped', 'pending', null, transaction);
178
+ return false;
179
+ });
180
+ }
181
+ async start(id, now = Date.now(), multiple = false, transaction) {
182
+ const claim = () => this.database.query(`UPDATE CronTriggers SET state='running', started_at=$now WHERE id=$id AND state='queued'
183
+ AND ($multiple OR NOT EXISTS (SELECT 1 FROM CronTriggers AS active
184
+ WHERE active.cron_id=CronTriggers.cron_id AND active.state='running'))`, { transaction, bind: { id, now, multiple: Number(multiple) }, type: sequelize_1.QueryTypes.BULKUPDATE });
185
+ let changed = await claim();
186
+ if (!changed && !multiple && !transaction) {
187
+ const [task] = await this.database.query("SELECT cron_id FROM CronTriggers WHERE id=$id AND state='queued'", { bind: { id }, type: sequelize_1.QueryTypes.SELECT });
188
+ if (task && await this.recoverSystemOwners(task.cron_id))
189
+ changed = await claim();
190
+ }
191
+ return changed === 1;
192
+ }
193
+ async claimManual(id, snapshot, token, independent) {
194
+ return this.database.transaction(async (transaction) => {
195
+ var _a;
196
+ // The write transaction orders a configuration save and a manual claim.
197
+ const rows = await this.database.query(`SELECT 1 FROM Crontabs WHERE id=$cronId AND recovery_from IS $revision
198
+ AND command=$command AND COALESCE(isDisabled,0)=$disabled
199
+ AND COALESCE(allow_multiple_instances,0)=$multiple
200
+ AND ($independent OR (status=3 AND queued_token=$token))`, { transaction, type: sequelize_1.QueryTypes.SELECT, bind: { cronId: snapshot.id, revision: (_a = snapshot.recovery_from) !== null && _a !== void 0 ? _a : null,
201
+ command: snapshot.command, disabled: snapshot.isDisabled || 0, multiple: snapshot.allow_multiple_instances || 0,
202
+ independent: Number(independent), token } });
203
+ if (!rows.length)
204
+ return 'changed';
205
+ if (!independent)
206
+ await this.recoverSystemOwners(snapshot.id, transaction);
207
+ return await this.start(id, Date.now(), independent, transaction) ? 'started' : 'overlap';
208
+ });
209
+ }
210
+ async finish(id, state, reason = null, code = null, transaction, finishedAt) {
211
+ // A managed supervisor can observe the clock moving backwards during a run.
212
+ // Clients supply their own timestamps; validate those against the recorded start.
213
+ return this.database.query(`UPDATE CronTriggers SET state=$state, reason=$reason, exit_code=$code,
214
+ started_at=CASE WHEN $state='skipped' THEN NULL ELSE started_at END,
215
+ finished_at=COALESCE(CASE WHEN owner IS NOT NULL OR $finishedAt >= started_at THEN $finishedAt END,CASE WHEN state='unknown' THEN finished_at END,$now)
216
+ WHERE id=$id AND (state IN ('running','queued') OR
217
+ (state='unknown' AND $state IN ('finished','failed','stopped')))`, { transaction, type: sequelize_1.QueryTypes.BULKUPDATE, bind: { id, state, reason, code, finishedAt: finishedAt !== null && finishedAt !== void 0 ? finishedAt : null, now: Date.now() } });
218
+ }
219
+ // A child close is an independent receipt when either Shell callback is lost.
220
+ async complete(id, state, reason, code, finishedAt, report) {
221
+ const sample = await this.readScriptSample(id);
222
+ await this.database.transaction(async (transaction) => {
223
+ await this.saveScriptSample(id, sample, transaction);
224
+ await this.completeCommandExit(id, state, reason, code, transaction, undefined, finishedAt, report);
225
+ });
226
+ if (sample)
227
+ await fs_1.promises.unlink(sample.marker).catch(() => { });
228
+ }
229
+ async completeCommandExit(id, state, reason, code, transaction, receipt, finishedAt, report, recoveredCopies) {
230
+ var _a, _b;
231
+ const file = (0, managedExit_cjs_1.receiptPath)(id);
232
+ let pending = file ? await this.pendingExit(id, transaction) : undefined;
233
+ const [saved] = file ? await this.database.query(`SELECT b.*,u.outcome AS unmatched_outcome,u.finished_at AS unmatched_time,EXISTS(SELECT 1 FROM CronBoundExitConflicts WHERE trigger_id=$id) AS conflicted
234
+ FROM (SELECT 1) LEFT JOIN CronLegacyExitBookings b ON b.trigger_id=$id LEFT JOIN CronUnmatchedBoundExits u ON u.trigger_id=$id`, { bind: { id }, transaction, type: sequelize_1.QueryTypes.SELECT }) : [];
235
+ const booking = (saved === null || saved === void 0 ? void 0 : saved.trigger_id) ? saved : undefined;
236
+ // Every version-1 publication has the same evidentiary weight, regardless of its path.
237
+ const recovered = recoveredCopies !== null && recoveredCopies !== void 0 ? recoveredCopies : (file ? await Promise.all((await (0, managedExit_cjs_1.retiringExits)())
238
+ .filter(copy => copy.id === id).map(copy => (0, managedExit_cjs_1.readExit)(id, copy.file))) : []);
239
+ const published = receipt === undefined && file ? await (0, managedExit_cjs_1.readExit)(id) : receipt;
240
+ const files = [published, ...recovered];
241
+ const candidates = [...files, ...files.map(copy => copy === null || copy === void 0 ? void 0 : copy.namedExit), report === 'legacy' ? undefined : report]
242
+ .filter((value) => (value === null || value === void 0 ? void 0 : value.version) === 1);
243
+ const bound = file && candidates[0] ? Object.assign(Object.assign({}, candidates[0]), { file }) : undefined;
244
+ const tuples = candidates.map(value => observationKey(id, value));
245
+ if (booking === null || booking === void 0 ? void 0 : booking.bound)
246
+ tuples.push({ id, outcome: booking.outcome, time: booking.finished_at });
247
+ if ((saved === null || saved === void 0 ? void 0 : saved.unmatched_time) != null && saved.unmatched_outcome != null) {
248
+ tuples.push({ id, outcome: saved.unmatched_outcome, time: saved.unmatched_time });
249
+ }
250
+ const first = tuples[0];
251
+ if ((saved === null || saved === void 0 ? void 0 : saved.conflicted) || tuples.some(tuple => tuple.time !== first.time || tuple.outcome !== first.outcome)) {
252
+ await this.disputeBoundExit(id, tuples, transaction);
253
+ if (saved.unmatched_time != null)
254
+ await this.database.query('DELETE FROM CronUnmatchedBoundExits WHERE trigger_id=$id', { bind: { id }, transaction });
255
+ this.retireDuplicatePublications(id, recovered, transaction);
256
+ if (!(saved === null || saved === void 0 ? void 0 : saved.conflicted)) {
257
+ if (booking) {
258
+ await this.withdrawBooking(booking, transaction);
259
+ await this.database.query('DELETE FROM CronLegacyExitBookings WHERE trigger_id=$id', { bind: { id }, transaction });
260
+ }
261
+ if (await this.invalidateBookedTrigger(id, transaction))
262
+ await this.deferExit(id, transaction);
263
+ }
264
+ else if ((pending === null || pending === void 0 ? void 0 : pending.state) === 'running')
265
+ await this.deferExit(id, transaction);
266
+ return;
267
+ }
268
+ for (const copy of recovered) {
269
+ if ((copy === null || copy === void 0 ? void 0 : copy.version) === 1)
270
+ this.retireReceiptAfterCommit(id, copy.file, transaction, 'bound-copy', copy);
271
+ }
272
+ if (bound && !pending && saved.unmatched_time == null) {
273
+ // After history pruning the booking can disappear with its daily row.
274
+ // Before releasing a verified replay, retain just its tuple so a later
275
+ // conflicting file can still be recognized without recreating that day.
276
+ await this.database.query(`INSERT OR IGNORE INTO CronUnmatchedBoundExits(trigger_id,outcome,finished_at)
277
+ SELECT $id,$outcome,$time WHERE NOT EXISTS (SELECT 1 FROM CronTriggers WHERE id=$id)`, { bind: observationKey(id, bound), transaction });
278
+ }
279
+ const start = (_a = booking === null || booking === void 0 ? void 0 : booking.started_at) !== null && _a !== void 0 ? _a : ((pending === null || pending === void 0 ? void 0 : pending.owner) ? pending.started_at : null);
280
+ const observation = start != null && finishedAt !== undefined && finishedAt >= start &&
281
+ (0, managedExit_cjs_1.validExit)(code, reason, finishedAt) && state === (code === 0 ? 'finished' : 'failed')
282
+ ? { code, signal: reason, time: finishedAt } : undefined;
283
+ if (booking && !booking.bound && (bound || (observation && (booking.outcome !== observationKey(id, observation).outcome ||
284
+ booking.finished_at !== observation.time)))) {
285
+ const retained = await this.reviseLegacyBooking(booking, bound, transaction);
286
+ if (!retained || !bound) {
287
+ if (retained)
288
+ await this.deferExit(id, transaction, observation);
289
+ else if (file)
290
+ this.retireReceiptAfterCommit(id, file, transaction, 'exit', published);
291
+ return;
292
+ }
293
+ pending = await this.pendingExit(id, transaction);
294
+ }
295
+ if (file && !pending) {
296
+ if (bound && !booking) {
297
+ const [pruned] = await this.database.query('SELECT trigger_id,cron_id,source,started_at FROM CronPrunedUnknownRuns WHERE trigger_id=$id', { bind: { id }, transaction, type: sequelize_1.QueryTypes.SELECT });
298
+ if (pruned) {
299
+ await this.bookPrunedExit(pruned, false, bound, transaction);
300
+ await this.database.query('DELETE FROM CronPrunedUnknownRuns WHERE trigger_id=$id', { bind: { id }, transaction });
301
+ }
302
+ }
303
+ await this.settleInstance(id, transaction);
304
+ this.retireReceiptAfterCommit(id, file, transaction, 'exit', published);
305
+ return;
306
+ }
307
+ if ((pending === null || pending === void 0 ? void 0 : pending.finished_at) != null && ['finished', 'failed', 'stopped'].includes(pending.state)) {
308
+ // An earlier panel may have committed the trigger before claiming its statistic.
309
+ await this.completeInTransaction(id, pending.state, pending.reason, pending.exit_code, transaction, undefined, pending.finished_at);
310
+ if (file)
311
+ this.retireReceiptAfterCommit(id, file, transaction, 'exit', published);
312
+ return;
313
+ }
314
+ if ((pending === null || pending === void 0 ? void 0 : pending.stop_exit_verified) && pending.stop_exit_at != null) {
315
+ // The outcome was verified before the last worker finished checking the process tree.
316
+ await this.completeInTransaction(id, 'stopped', 'cancelled', pending.exit_code, transaction, undefined, pending.stop_exit_at);
317
+ this.retireReceiptAfterCommit(id, file, transaction, 'exit');
318
+ return;
319
+ }
320
+ // A truncated publication is different from no publication. In particular
321
+ // a killed supervisor cannot attest to the script's own exit status.
322
+ const unreadable = recovered.some(copy => copy === null || (copy && copy.version !== 1 && isBoundPublication(copy.file)));
323
+ const exit = (_b = bound !== null && bound !== void 0 ? bound : published) !== null && _b !== void 0 ? _b : (unreadable ? null : published);
324
+ if (exit && exit.version !== 1 && !(booking === null || booking === void 0 ? void 0 : booking.bound)) {
325
+ if (observation)
326
+ await this.saveExitObservation(id, observation, transaction);
327
+ if ((pending === null || pending === void 0 ? void 0 : pending.started_at) == null || exit.time < pending.started_at ||
328
+ !await this.hasExitObservation(id, exit, transaction)) {
329
+ await this.deferExit(id, transaction);
330
+ return;
331
+ }
332
+ }
333
+ if (exit && (pending === null || pending === void 0 ? void 0 : pending.started_at) != null && !(booking === null || booking === void 0 ? void 0 : booking.bound)) {
334
+ // Track the exact contribution until its history and retained statistic expire.
335
+ await this.database.query(`INSERT OR IGNORE INTO CronLegacyExitBookings(trigger_id,cron_id,source,started_at,finished_at,outcome,day,bound)
336
+ SELECT id,cron_id,source,started_at,$time,$outcome,$day,$bound FROM CronTriggers WHERE id=$id`, { bind: Object.assign(Object.assign({}, observationKey(id, exit)), { bound: Number(exit.version === 1), day: (0, dayjs_1.default)(exit.time).format('YYYY-MM-DD') }), transaction });
337
+ await this.database.query('DELETE FROM CronExitObservations WHERE trigger_id=$id', { bind: { id }, transaction });
338
+ if (bound && (saved === null || saved === void 0 ? void 0 : saved.unmatched_time) != null)
339
+ await this.database.query('DELETE FROM CronUnmatchedBoundExits WHERE trigger_id=$id', { bind: { id }, transaction });
340
+ }
341
+ // A signal on the bound supervisor before its first write says nothing about
342
+ // the command it was waiting for. A verified stop has its own durable claim.
343
+ const supervisorKilled = (pending === null || pending === void 0 ? void 0 : pending.command_identity) && !pending.stop_requested &&
344
+ code === null && state === 'stopped' && (reason === null || reason === void 0 ? void 0 : reason.startsWith('SIG'));
345
+ if (pending && pending.owner && pending.started_at !== null &&
346
+ (exit === null || (!exit && (pending.exit_pending || supervisorKilled || report === 'legacy')))) {
347
+ await this.deferExit(id, transaction, observation);
348
+ return;
349
+ }
350
+ if (exit) {
351
+ await this.completeInTransaction(id, exit.signal || exit.code !== 0 ? 'failed' : 'finished', exit.signal, exit.code, transaction, undefined, exit.time, true);
352
+ this.retireReceiptAfterCommit(id, exit.file, transaction, 'exit');
353
+ }
354
+ else if (state === 'skipped') {
355
+ await this.finish(id, state, reason, code, transaction);
356
+ await this.settleInstance(id, transaction);
357
+ }
358
+ else {
359
+ await this.completeInTransaction(id, state, reason, code, transaction, undefined, finishedAt);
360
+ }
361
+ }
362
+ async withdrawBooking(booking, transaction) {
363
+ const { trigger_id: id, stat_id: stat } = booking;
364
+ const elapsed = Math.max(0, booking.finished_at - booking.started_at);
365
+ if (stat !== null) {
366
+ // Only the row that received this exact contribution can be debited. A deleted day stays deleted.
367
+ await this.database.query(`UPDATE CrontabStats SET run_count=run_count-1, success_count=success_count-$success,
368
+ fail_count=fail_count-$failure,total_time=total_time-$elapsed,updatedAt=CURRENT_TIMESTAMP,
369
+ max_time=MAX(COALESCE(fixed_max_time,0),COALESCE((SELECT MAX(MAX(0,finished_at-started_at))
370
+ FROM CronLegacyExitBookings WHERE stat_id=$stat AND trigger_id<>$id),0)) WHERE id=$stat`, { bind: { stat, id, elapsed, success: Number(!booking.stopped && booking.outcome === '0'),
371
+ failure: Number(!booking.stopped && booking.outcome !== '0') }, transaction });
372
+ await this.database.query('DELETE FROM CrontabStats WHERE id=$stat AND run_count=0', { bind: { stat }, transaction });
373
+ }
374
+ }
375
+ async invalidateBookedTrigger(id, transaction) {
376
+ const [trigger] = await this.database.query('SELECT instance_id,state,cron_id FROM CronTriggers WHERE id=$id AND started_at IS NOT NULL', { bind: { id }, type: sequelize_1.QueryTypes.SELECT, transaction });
377
+ if (!trigger)
378
+ return false;
379
+ const ref = trigger.cron_id;
380
+ await this.database.query(`UPDATE CronTriggers SET counted=0,exit_pending=1,stop_exit_verified=NULL,stop_exit_at=NULL,
381
+ exit_code=NULL,reason=NULL,state=CASE WHEN state='running' THEN state ELSE 'unknown' END WHERE id=$id`, { bind: { id }, transaction });
382
+ if (trigger.instance_id !== null && trigger.state !== 'running') {
383
+ await this.database.query('UPDATE RunningInstances SET status=4,exit_code=NULL,updatedAt=CURRENT_TIMESTAMP WHERE id=$instance AND cron_id=$ref', { bind: { instance: trigger.instance_id, ref }, transaction });
384
+ await this.database.query('UPDATE Crontabs SET last_running_time=NULL WHERE id=$ref AND last_instance_id=$instance', { bind: { ref, instance: trigger.instance_id }, transaction });
385
+ }
386
+ return true;
387
+ }
388
+ async disputeBoundExit(id, tuples, transaction) {
389
+ if (!tuples.length)
390
+ return;
391
+ await this.database.query(`INSERT OR IGNORE INTO CronBoundExitConflicts(trigger_id,outcome,finished_at)
392
+ SELECT $id,json_extract(value,'$.outcome'),json_extract(value,'$.time') FROM json_each($tuples)`, { bind: { id, tuples: JSON.stringify(tuples) }, transaction });
393
+ }
394
+ async bookPrunedExit(run, stopped, exit, transaction) {
395
+ const day = (0, dayjs_1.default)(exit.time).format('YYYY-MM-DD');
396
+ const state = stopped ? 'stopped' : exit.code === 0 ? 'finished' : 'failed';
397
+ await (0, cronStatistics_1.addDailyExit)(this.database, run.cron_id, day, state, Math.max(0, exit.time - run.started_at), true, transaction);
398
+ await this.database.query(`INSERT INTO CronLegacyExitBookings(trigger_id,cron_id,source,started_at,finished_at,outcome,day,stopped,bound,stat_id)
399
+ VALUES($id,$ref,$source,$start,$time,$outcome,$day,$stopped,1,
400
+ (SELECT id FROM CrontabStats WHERE ref_id=$ref AND date=$day
401
+ AND NOT EXISTS (SELECT 1 FROM CronStatRetention WHERE id=1 AND first_day>$day)))
402
+ ON CONFLICT(trigger_id) DO UPDATE SET bound=1,disputed=0,outcome=excluded.outcome,finished_at=excluded.finished_at,
403
+ day=excluded.day,stat_id=excluded.stat_id`, { bind: Object.assign(Object.assign({}, observationKey(run.trigger_id, exit)), { ref: run.cron_id, source: run.source, start: run.started_at, day, stopped: Number(stopped) }), transaction });
404
+ }
405
+ async reviseLegacyBooking(booking, bound, transaction) {
406
+ const id = booking.trigger_id;
407
+ await this.withdrawBooking(booking, transaction);
408
+ const retained = await this.invalidateBookedTrigger(id, transaction);
409
+ if (!retained) {
410
+ if (!bound) {
411
+ await this.database.query('UPDATE CronLegacyExitBookings SET disputed=1,stat_id=NULL WHERE trigger_id=$id', { bind: { id }, transaction });
412
+ }
413
+ else {
414
+ await this.bookPrunedExit(booking, Boolean(booking.stopped), bound, transaction);
415
+ }
416
+ return false;
417
+ }
418
+ await this.database.query('DELETE FROM CronLegacyExitBookings WHERE trigger_id=$id', { bind: { id }, transaction });
419
+ if (!bound)
420
+ await this.database.query(`INSERT OR IGNORE INTO CronExitObservations(trigger_id,outcome,finished_at)
421
+ VALUES($id,$outcome,$time)`, { bind: { id, outcome: booking.outcome, time: booking.finished_at }, transaction });
422
+ return true;
423
+ }
424
+ retireDuplicatePublications(id, copies, transaction) {
425
+ // Independent scans must agree about which file to keep even if they see
426
+ // different subsets. Only newer per-writer publications can be discarded.
427
+ const witnesses = new Map();
428
+ const redundant = [];
429
+ // Prefer a JSON copy readable by older panels. Compare full paths within
430
+ // each format so concurrent collectors always choose the same survivor.
431
+ const rank = (file) => ((0, managedExit_cjs_1.isMetadataReceipt)(file) ? '1' : '0') + file;
432
+ for (const copy of copies) {
433
+ if ((copy === null || copy === void 0 ? void 0 : copy.version) !== 1 || copy.namedExit || !(0, path_1.basename)(copy.file).startsWith('.pending.'))
434
+ continue;
435
+ const { outcome, time } = observationKey(id, copy);
436
+ const key = JSON.stringify([outcome, time]);
437
+ const previous = witnesses.get(key);
438
+ if (previous && previous !== copy.file) {
439
+ redundant.push({ file: rank(previous) < rank(copy.file) ? copy.file : previous, key, outcome, time });
440
+ }
441
+ if (!previous || rank(copy.file) < rank(previous))
442
+ witnesses.set(key, copy.file);
443
+ }
444
+ if (!redundant.length)
445
+ return;
446
+ transaction.afterCommit(async () => {
447
+ // Sequelize also invokes this hook after a failed COMMIT. Verify the
448
+ // specific tuple in a separate snapshot, including on an existing dispute.
449
+ try {
450
+ const rows = await this.database.query('SELECT outcome,finished_at FROM CronBoundExitConflicts WHERE trigger_id=$id', { bind: { id }, transaction: null, type: sequelize_1.QueryTypes.SELECT });
451
+ const committed = new Set(rows.map(row => JSON.stringify([row.outcome, row.finished_at])));
452
+ for (const copy of redundant) {
453
+ if (!committed.has(copy.key))
454
+ continue;
455
+ const keeper = await (0, managedExit_cjs_1.readExit)(id, witnesses.get(copy.key));
456
+ if ((keeper === null || keeper === void 0 ? void 0 : keeper.version) === 1 && keeper.time === copy.time && observationKey(id, keeper).outcome === copy.outcome) {
457
+ await (0, managedExit_cjs_1.retireLegacyFile)(id, copy.file, copy).catch(() => { });
458
+ }
459
+ }
460
+ }
461
+ catch ( /* Retry on the next recovery pass. */_a) { /* Retry on the next recovery pass. */ }
462
+ });
463
+ }
464
+ retireReceiptAfterCommit(id, file, transaction, kind, observed) {
465
+ // Sequelize 6 runs afterCommit even when COMMIT itself failed. Check a
466
+ // separate committed snapshot before deleting the only durable outcome.
467
+ transaction.afterCommit(async () => {
468
+ try {
469
+ const pendingCondition = kind === 'start' ? 'script_started_at IS NULL' : 'counted=0';
470
+ const [saved] = await this.database.query(`SELECT EXISTS(SELECT 1 FROM CronTriggers WHERE id=$id AND ${pendingCondition}) AS pending,
471
+ EXISTS(SELECT 1 FROM CronBoundExitConflicts WHERE trigger_id=$id) AS conflicted,
472
+ (b.trigger_id IS NULL AND u.trigger_id IS NOT NULL) AS unmatched,
473
+ COALESCE(b.outcome,u.outcome) AS outcome,COALESCE(b.finished_at,u.finished_at) AS finished_at,
474
+ COALESCE(b.bound,u.trigger_id IS NOT NULL) AS bound FROM (SELECT 1)
475
+ LEFT JOIN CronLegacyExitBookings b ON b.trigger_id=$id LEFT JOIN CronUnmatchedBoundExits u ON u.trigger_id=$id`, { bind: { id }, transaction: null, type: sequelize_1.QueryTypes.SELECT });
476
+ if (saved.pending || (kind !== 'start' && saved.conflicted))
477
+ return;
478
+ if (saved.outcome !== null && saved.finished_at !== null && kind !== 'start') {
479
+ if (saved.unmatched) {
480
+ // A legacy public name may be unreadable until claimed. Verify the
481
+ // moved bytes directly against the durable unmatched observation.
482
+ await (0, managedExit_cjs_1.retireLegacyFile)(id, file, { outcome: saved.outcome, time: saved.finished_at });
483
+ return;
484
+ }
485
+ // After a failed correction the old booking is still visible.
486
+ if (kind === 'bound-copy' && !saved.bound)
487
+ return;
488
+ const current = await (0, managedExit_cjs_1.readExit)(id, file);
489
+ if (current && ((saved.bound && current.version !== 1) || (current.time === saved.finished_at &&
490
+ observationKey(id, current).outcome === saved.outcome && (saved.bound || current.version !== 1)))) {
491
+ await (0, managedExit_cjs_1.retireLegacyFile)(id, file, saved.bound ? { outcome: saved.outcome, time: saved.finished_at } : undefined);
492
+ }
493
+ return;
494
+ }
495
+ if (kind === 'start')
496
+ await fs_1.promises.rm(file, { force: true });
497
+ else if ((observed === null || observed === void 0 ? void 0 : observed.version) !== 1)
498
+ await (0, managedExit_cjs_1.retireLegacyFile)(id, file);
499
+ }
500
+ catch ( /* Keep the receipt for the next recovery pass. */_a) { /* Keep the receipt for the next recovery pass. */ }
501
+ });
502
+ }
503
+ async replayRetiringExits(transaction) {
504
+ var _a;
505
+ const byId = new Map();
506
+ const unreadable = new Set();
507
+ for (const { id, file } of await (0, managedExit_cjs_1.retiringExits)()) {
508
+ const exit = await (0, managedExit_cjs_1.readExit)(id, file);
509
+ if (exit === undefined)
510
+ continue;
511
+ if (exit === null || (exit.version !== 1 && isBoundPublication(file))) {
512
+ unreadable.add(id);
513
+ continue;
514
+ }
515
+ if (exit.version !== 1) {
516
+ // Inspect the atomically moved bytes even when a stale temporary file is being replaced.
517
+ await (0, managedExit_cjs_1.retireLegacyFile)(id, file).catch(() => { });
518
+ continue;
519
+ }
520
+ const copies = (_a = byId.get(id)) !== null && _a !== void 0 ? _a : [];
521
+ copies.push(exit);
522
+ byId.set(id, copies);
523
+ }
524
+ if (unreadable.size) {
525
+ // Retention runs this scan before deletion. Keep unresolved history for
526
+ // later repair without ending a live process solely on damaged bytes.
527
+ await this.database.query(`UPDATE CronTriggers SET exit_pending=1 WHERE counted=0 AND state='unknown'
528
+ AND exit_pending IS NOT 1 AND owner IS NOT NULL AND started_at IS NOT NULL
529
+ AND id IN (SELECT value FROM json_each($ids))`, { transaction, bind: { ids: JSON.stringify([...unreadable]) } });
530
+ }
531
+ for (const [id, copies] of byId) {
532
+ const settle = async (tx) => {
533
+ await this.recoverScriptSample(id, tx);
534
+ await this.completeCommandExit(id, 'unknown', null, null, tx, undefined, undefined, undefined, copies);
535
+ };
536
+ if (transaction)
537
+ await settle(transaction);
538
+ else
539
+ await this.database.transaction(settle);
540
+ }
541
+ return byId;
542
+ }
543
+ async pendingExit(id, transaction) {
544
+ const [row] = await this.database.query(`SELECT state,reason,exit_code,started_at,finished_at,owner,command_identity,stop_requested,stop_exit_verified,stop_exit_at,exit_pending
545
+ FROM CronTriggers WHERE id=$id AND counted=0`, { bind: { id }, transaction, type: sequelize_1.QueryTypes.SELECT });
546
+ return row;
547
+ }
548
+ async hasExitObservation(id, exit, transaction) {
549
+ const [match] = await this.database.query(`SELECT 1 FROM CronExitObservations WHERE trigger_id=$id GROUP BY trigger_id
550
+ HAVING COUNT(*)=1 AND MAX(outcome)=$outcome AND MAX(finished_at)=$time`, { bind: observationKey(id, exit), type: sequelize_1.QueryTypes.SELECT, transaction });
551
+ return Boolean(match);
552
+ }
553
+ async saveExitObservation(id, observation, transaction) {
554
+ await this.database.query(`INSERT INTO CronExitObservations(trigger_id,outcome,finished_at)
555
+ SELECT $id,$outcome,$time WHERE NOT EXISTS
556
+ (SELECT 1 FROM CronExitObservations WHERE trigger_id=$id LIMIT 1 OFFSET 1)
557
+ ON CONFLICT(trigger_id,outcome,finished_at) DO NOTHING`, { bind: observationKey(id, observation), transaction });
558
+ }
559
+ async deferExit(id, transaction, observation) {
560
+ if (observation)
561
+ await this.saveExitObservation(id, observation, transaction);
562
+ await this.database.query('UPDATE CronTriggers SET exit_pending=1 WHERE id=$id AND exit_pending IS NOT 1', { bind: { id }, transaction });
563
+ // A signalled stop remains running until all of its descendants are gone.
564
+ await this.database.query(`UPDATE CronTriggers SET state='unknown',reason=NULL,exit_code=NULL,
565
+ finished_at=COALESCE(finished_at,$now) WHERE id=$id AND state='running'
566
+ AND NOT EXISTS (SELECT 1 FROM CronStopRequests s WHERE s.instance_id=CronTriggers.instance_id
567
+ AND s.targets IS NOT NULL AND s.signalled=1)`, { bind: { id, now: Date.now() }, transaction });
568
+ await this.settleInstance(id, transaction);
569
+ }
570
+ async retryPendingExits() {
571
+ const rows = await this.database.query(`SELECT id FROM CronTriggers WHERE exit_pending=1 AND
572
+ NOT EXISTS (SELECT 1 FROM CronBoundExitConflicts WHERE trigger_id=CronTriggers.id)`, { type: sequelize_1.QueryTypes.SELECT });
573
+ for (const { id } of rows) {
574
+ const exit = await (0, managedExit_cjs_1.readExit)(id);
575
+ if (exit && (exit.version === 1 || await this.hasExitObservation(id, exit))) {
576
+ // Carry a verified bound receipt across a concurrent file replacement.
577
+ // Unbound evidence must still match inside the writer transaction.
578
+ await this.complete(id, 'unknown', null, null, undefined, exit.version === 1 ? exit : undefined);
579
+ }
580
+ }
581
+ // A canonical-only file can reappear after startup already marked its owner
582
+ // unknown. Probe IDs found on disk so missing receipts cost no per-run work.
583
+ const recovered = await this.replayRetiringExits();
584
+ const files = (await (0, managedExit_cjs_1.publishedExits)()).filter(id => !recovered.has(id));
585
+ if (files.length) {
586
+ const candidates = await this.database.query(`SELECT value AS id FROM json_each($files) WHERE
587
+ EXISTS (SELECT 1 FROM CronTriggers WHERE id=value AND state='unknown' AND reason='restart'
588
+ AND counted=0 AND owner IS NOT NULL AND started_at IS NOT NULL) OR
589
+ EXISTS (SELECT 1 FROM CronPrunedUnknownRuns WHERE trigger_id=value) OR
590
+ EXISTS (SELECT 1 FROM CronLegacyExitBookings WHERE trigger_id=value) OR
591
+ EXISTS (SELECT 1 FROM CronBoundExitConflicts WHERE trigger_id=value) OR
592
+ EXISTS (SELECT 1 FROM CronUnmatchedBoundExits WHERE trigger_id=value)`, { bind: { files: JSON.stringify(files) }, type: sequelize_1.QueryTypes.SELECT });
593
+ for (const { id } of candidates) {
594
+ const exit = await (0, managedExit_cjs_1.readExit)(id);
595
+ if ((exit === null || exit === void 0 ? void 0 : exit.version) === 1)
596
+ await this.complete(id, 'unknown', null, null, undefined, exit);
597
+ }
598
+ }
599
+ await this.collectPublishedScriptStarts();
600
+ }
601
+ async collectPublishedScriptStarts() {
602
+ const files = await (0, managedExit_cjs_1.publishedScriptStarts)();
603
+ if (!files.length)
604
+ return;
605
+ // Only probe existing executions. Keep live markers in place so another
606
+ // instrumented command in the same execution cannot replace the first sample.
607
+ const rows = await this.database.query(`SELECT id,counted,script_started_at FROM CronTriggers WHERE id IN (SELECT value FROM json_each($ids))
608
+ AND started_at IS NOT NULL AND (script_started_at IS NULL OR counted=1)`, { bind: { ids: JSON.stringify(files.map(({ id }) => id)) }, type: sequelize_1.QueryTypes.SELECT });
609
+ for (const row of rows) {
610
+ const sample = await this.readScriptSample(row.id);
611
+ if (!sample)
612
+ continue;
613
+ await this.database.transaction(async (transaction) => {
614
+ if (row.script_started_at === null)
615
+ await this.saveScriptSample(row.id, sample, transaction);
616
+ if (row.counted)
617
+ this.retireReceiptAfterCommit(row.id, sample.marker, transaction, 'start');
618
+ });
619
+ }
620
+ }
621
+ async replayPublishedExits(transaction) {
622
+ const recovered = await this.replayRetiringExits(transaction);
623
+ // Entry instrumentation can outlive its committed transaction even if the
624
+ // exit file was already deleted. An unregistered entry may still be live.
625
+ const exits = new Set(await (0, managedExit_cjs_1.publishedExits)());
626
+ for (const { id, file } of await (0, managedExit_cjs_1.publishedScriptStarts)()) {
627
+ const [row] = await this.database.query('SELECT counted,script_started_at FROM CronTriggers WHERE id=$id', { bind: { id }, transaction, type: sequelize_1.QueryTypes.SELECT });
628
+ // After pruning the trigger, a matching supervisor exit still identifies
629
+ // this panel's retired run. A start file alone cannot establish that.
630
+ if (row ? row.counted && row.script_started_at !== null : exits.has(id)) {
631
+ this.retireReceiptAfterCommit(id, file, transaction, 'start');
632
+ }
633
+ }
634
+ for (const id of exits) {
635
+ if (recovered.has(id))
636
+ continue;
637
+ const pending = await this.pendingExit(id, transaction);
638
+ if (!pending) {
639
+ await this.completeCommandExit(id, 'unknown', 'restart', null, transaction, undefined, undefined, undefined, []);
640
+ }
641
+ else if (pending.owner && pending.started_at !== null) {
642
+ const exit = await (0, managedExit_cjs_1.readExit)(id);
643
+ if (exit === undefined)
644
+ continue;
645
+ await this.recoverScriptSample(id, transaction);
646
+ await this.completeCommandExit(id, 'unknown', 'restart', null, transaction, exit, undefined, undefined, []);
647
+ }
648
+ }
649
+ }
650
+ // Original registration order breaks ties even when upgrade adoption runs later.
651
+ async claimSummary(cronId, instance, seconds, transaction, observedStart, duration = null) {
652
+ await this.database.query(`UPDATE Crontabs SET last_instance_id=$instance,
653
+ last_execution_time=$seconds,last_running_time=$duration WHERE id=$cronId AND
654
+ (last_execution_time IS NULL OR last_execution_time<$seconds OR
655
+ (last_execution_time=$seconds AND (last_instance_id IS NULL OR
656
+ ($observedStart AND last_instance_id<$instance))))`, { transaction, bind: { cronId, instance, seconds, duration, observedStart: Number(observedStart) } });
657
+ }
658
+ async completeInTransaction(id, state, reason, code, transaction, elapsedMs, finishedAt, verifiedExit = false) {
659
+ var _a;
660
+ if (await this.shouldStop(id, transaction)) {
661
+ state = 'stopped';
662
+ reason = 'cancelled';
663
+ // The command can exit before its TERM-resistant descendants. Keep the
664
+ // receipt running until the stop operation has verified the whole tree.
665
+ const waiting = await this.database.query(`UPDATE CronTriggers SET
666
+ exit_code=CASE WHEN stop_exit_at IS NULL OR ($verified AND stop_exit_verified IS NOT 1) THEN $code ELSE exit_code END,
667
+ stop_exit_at=CASE WHEN stop_exit_at IS NULL OR ($verified AND stop_exit_verified IS NOT 1) THEN $now ELSE stop_exit_at END,
668
+ stop_exit_verified=CASE WHEN $verified THEN 1 ELSE stop_exit_verified END
669
+ WHERE id=$id AND state='running' AND stop_requested=1 AND instance_id IN
670
+ (SELECT instance_id FROM CronStopRequests WHERE targets IS NOT NULL AND signalled=1)`, { transaction, bind: { id, code, now: finishedAt !== null && finishedAt !== void 0 ? finishedAt : Date.now(), verified: Number(verifiedExit) }, type: sequelize_1.QueryTypes.BULKUPDATE });
671
+ if (waiting)
672
+ return;
673
+ }
674
+ else if (state === 'stopped' && (reason === null || reason === void 0 ? void 0 : reason.startsWith('SIG'))) {
675
+ state = 'failed';
676
+ }
677
+ const changed = await this.finish(id, state, reason, code, transaction, finishedAt);
678
+ const [row] = await this.database.query(`SELECT cron_id, instance_id, log_path, started_at, finished_at, exit_code FROM CronTriggers WHERE id=$id
679
+ AND state IN ('finished','failed','stopped') AND started_at IS NOT NULL AND counted=0`, { transaction, bind: { id }, type: sequelize_1.QueryTypes.SELECT });
680
+ await this.settleInstance(id, transaction);
681
+ if (!row)
682
+ return;
683
+ const duration = elapsedMs !== null && elapsedMs !== void 0 ? elapsedMs : Math.max(0, row.finished_at - row.started_at);
684
+ if (changed && row.instance_id !== null) {
685
+ await this.database.query(`UPDATE Crontabs SET last_running_time=$duration
686
+ WHERE id=$cronId AND last_execution_time=$start AND (last_instance_id=$instance OR
687
+ (last_instance_id IS NULL AND $instance=(SELECT id FROM RunningInstances WHERE cron_id=$cronId
688
+ ORDER BY started_at DESC,id DESC LIMIT 1)))`, { transaction, bind: { cronId: row.cron_id,
689
+ start: Math.floor(row.started_at / 1000), instance: row.instance_id, duration: Math.floor(duration / 1000) } });
690
+ }
691
+ await (0, cronStatistics_1.recordCronResult)(this.database, row.cron_id, (_a = row.exit_code) !== null && _a !== void 0 ? _a : 1, duration, row.finished_at, id, transaction);
692
+ }
693
+ async hasBoundConflict(id, transaction) {
694
+ const [conflict] = await this.database.query('SELECT 1 FROM CronBoundExitConflicts WHERE trigger_id=$id', { bind: { id }, transaction, type: sequelize_1.QueryTypes.SELECT });
695
+ return Boolean(conflict);
696
+ }
697
+ // Old shell-only executions publish status and statistics independently.
698
+ // Either final receipt can settle that execution if the other was lost.
699
+ async recordShellResult(id, cronId, code, elapsedMs, now, finishedAt) {
700
+ return this.database.transaction(async (transaction) => {
701
+ if (await this.hasBoundConflict(id, transaction))
702
+ return;
703
+ const [row] = await this.database.query('SELECT owner,state FROM CronTriggers WHERE id=$id AND cron_id=$cronId', { transaction, type: sequelize_1.QueryTypes.SELECT, bind: { id, cronId } });
704
+ if (!row) {
705
+ if (finishedAt && finishedAt <= now) {
706
+ const [pruned] = await this.database.query('SELECT 1 FROM CronHistoryRetention WHERE id=1 AND cutoff>$end', { transaction, type: sequelize_1.QueryTypes.SELECT, bind: { end: finishedAt } });
707
+ if (pruned)
708
+ return;
709
+ }
710
+ throw new Error('Unknown trigger');
711
+ }
712
+ if (row.owner === null && (row.state === 'running' || row.state === 'unknown')) {
713
+ await this.completeInTransaction(id, code === 0 ? 'finished' : 'failed', null, code, transaction, elapsedMs, finishedAt);
714
+ }
715
+ else {
716
+ await (0, cronStatistics_1.recordCronResult)(this.database, cronId, code, elapsedMs, now, id, transaction);
717
+ }
718
+ });
719
+ }
720
+ async readScriptSample(id) {
721
+ if (!process.env.QL_DIR || !/^[a-z0-9-]{1,120}$/.test(id))
722
+ return;
723
+ const marker = (0, path_1.join)(process.env.QL_DIR, '.tmp', 'cron-start-' + id);
724
+ try {
725
+ const value = await fs_1.promises.readFile(marker, 'utf8');
726
+ if (/^\d{13}$/.test(value))
727
+ return { marker, time: Number(value) };
728
+ }
729
+ catch ( /* Entries without instrumentation have no sample. */_a) { /* Entries without instrumentation have no sample. */ }
730
+ }
731
+ async recoverScriptSample(id, transaction) {
732
+ const sample = await this.readScriptSample(id);
733
+ if (!sample)
734
+ return;
735
+ await this.saveScriptSample(id, sample, transaction);
736
+ this.retireReceiptAfterCommit(id, sample.marker, transaction, 'start');
737
+ }
738
+ async saveScriptSample(id, sample, transaction) {
739
+ if (sample)
740
+ await this.database.query(`UPDATE CronTriggers SET script_started_at=$time
741
+ WHERE id=$id AND script_started_at IS NULL AND started_at <= $time AND $time <= $now
742
+ AND (finished_at IS NULL OR state='unknown' OR $time <= finished_at)`, { transaction, bind: { time: sample.time, now: Date.now(), id } });
743
+ }
744
+ async isRunning(cronId, transaction) {
745
+ await this.recoverSystemOwners(cronId, transaction);
746
+ const rows = await this.database.query("SELECT 1 FROM CronTriggers WHERE cron_id=$cronId AND state='running' LIMIT 1", { bind: { cronId }, transaction, type: sequelize_1.QueryTypes.SELECT });
747
+ return rows.length !== 0;
748
+ }
749
+ async shellReport(id, cronId, system, running, log, seconds, exitCode, stopped = false, transaction, elapsedMs, finishedAt) {
750
+ if (!transaction)
751
+ return this.database.transaction(tx => this.shellReport(id, cronId, system, running, log, seconds, exitCode, stopped, tx, elapsedMs, finishedAt));
752
+ if (await this.hasBoundConflict(id, transaction))
753
+ return false;
754
+ if (system || executionIdentity_1.executionIdPattern.test(id)) {
755
+ // Standalone clients supply neither a scheduled instant nor a queue observation.
756
+ const dated = Number.isSafeInteger(seconds) && seconds > 0;
757
+ const start = dated ? seconds * 1000 : Date.now();
758
+ const standalone = executionIdentity_1.executionIdPattern.test(id) || id.startsWith('system-cli-');
759
+ const lastKnownTime = standalone && !running && dated && finishedAt && finishedAt >= start && finishedAt <= Date.now()
760
+ ? finishedAt : start;
761
+ await this.database.query(`INSERT INTO CronTriggers(id,cron_id,source,state,started_at,observed_at)
762
+ SELECT $id,$cronId,$source,'running',$start,$start
763
+ WHERE NOT EXISTS (SELECT 1 FROM CronHistoryRetention WHERE id=1 AND ($dated=0 OR cutoff>$lastKnownTime))
764
+ ON CONFLICT(id) DO NOTHING`, { transaction, bind: { id, cronId, start, lastKnownTime, dated: Number(dated), source: system ? 'system' : 'client' } });
765
+ }
766
+ await this.database.query(`UPDATE CronTriggers SET log_path=COALESCE(log_path,$log) WHERE id=$id AND cron_id=$cronId`, { transaction, bind: { id, cronId, log } });
767
+ if (!running) {
768
+ // For a managed command the wrapper may be only the first segment.
769
+ // Only its supervisor can report the whole command's exit.
770
+ const [legacy] = await this.database.query('SELECT 1 FROM CronTriggers WHERE id=$id AND cron_id=$cronId AND owner IS NULL', { transaction, type: sequelize_1.QueryTypes.SELECT, bind: { id, cronId } });
771
+ if (legacy) {
772
+ const state = stopped ? 'stopped' : exitCode == null ? 'unknown' : exitCode === 0 ? 'finished' : 'failed';
773
+ await this.completeInTransaction(id, state, null, exitCode !== null && exitCode !== void 0 ? exitCode : null, transaction, elapsedMs, finishedAt);
774
+ }
775
+ }
776
+ }
777
+ async reportLegacy(cronId, running, pid, log, seconds, elapsed, code) {
778
+ return this.database.transaction(transaction => this.applyLegacyReceipt(cronId, running, pid, log, seconds, elapsed, transaction, code));
779
+ }
780
+ async applyLegacyReceipt(cronId, running, pid, log, seconds, elapsed, transaction, code) {
781
+ var _a, _b, _c;
782
+ const start = seconds * 1000;
783
+ const receipt = 'legacy-' + (0, crypto_1.createHash)('sha256')
784
+ .update(JSON.stringify([cronId, pid, seconds, log || null])).digest('hex');
785
+ // A verified child stays attached to its supervisor even after the OS recycles its PID.
786
+ const [bound] = await this.database.query('SELECT 1 FROM CronShellBindings WHERE receipt=$receipt', { transaction, type: sequelize_1.QueryTypes.SELECT, bind: { receipt } });
787
+ if (bound)
788
+ return;
789
+ const rows = await this.database.query(`SELECT i.id AS instance,i.status,i.finished_at,i.exit_code,i.log_path,t.id,t.source FROM RunningInstances i
790
+ LEFT JOIN CronTriggers t ON t.instance_id=i.id WHERE i.cron_id=$cronId AND i.pid=$pid
791
+ AND (t.id IS NULL OR t.source='legacy' OR t.owner IS NOT NULL)
792
+ AND i.started_at=$seconds AND (i.log_path IS $log OR $log IS NULL OR i.log_path IS NULL) LIMIT 2`, { transaction, type: sequelize_1.QueryTypes.SELECT, bind: { cronId, pid, seconds, log: log || null } });
793
+ const [old] = rows;
794
+ if (rows.length > 1)
795
+ return;
796
+ if (old) {
797
+ if (!old.id && old.status === 4) {
798
+ const [expired] = await this.database.query('SELECT 1 FROM CronHistoryRetention WHERE cutoff>$end', { transaction, type: sequelize_1.QueryTypes.SELECT, bind: { end: ((_a = old.finished_at) !== null && _a !== void 0 ? _a : seconds) * 1000 } });
799
+ if (expired)
800
+ return;
801
+ }
802
+ if (old.status !== 0 && old.status !== 4) {
803
+ if (!old.id && old.finished_at != null) {
804
+ // The old panel owned the daily aggregate. Import its committed result
805
+ // without replaying an anonymous statistics increment.
806
+ const state = old.status === 1 ? 'finished' : old.status === 2 ? 'stopped' : 'failed';
807
+ const inserted = await this.database.query(`INSERT INTO CronTriggers
808
+ (id,cron_id,source,state,observed_at,started_at,finished_at,instance_id,log_path,exit_code,counted)
809
+ SELECT $id,$cronId,'legacy',$state,$start,$start,$end,$instance,$log,$exit,1
810
+ WHERE $end >= $start AND $end>=COALESCE((SELECT cutoff FROM CronHistoryRetention WHERE id=1),0)
811
+ AND NOT EXISTS (SELECT 1 FROM RunningInstances sibling
812
+ LEFT JOIN CronTriggers linked ON linked.instance_id=sibling.id
813
+ WHERE sibling.cron_id=$cronId
814
+ AND sibling.pid=$pid AND sibling.finished_at=$end/1000 AND sibling.id<>$instance
815
+ AND sibling.status IN (1,3) AND (linked.id IS NULL OR (linked.source='legacy' AND linked.owner IS NULL)))
816
+ ON CONFLICT DO NOTHING`, { transaction, type: sequelize_1.QueryTypes.BULKUPDATE,
817
+ bind: { id: receipt, cronId, pid, state, start, end: old.finished_at * 1000, instance: old.instance, log: old.log_path, exit: old.exit_code } });
818
+ if (inserted)
819
+ await this.claimSummary(cronId, old.instance, seconds, transaction, true, Math.max(0, old.finished_at - seconds));
820
+ }
821
+ return;
822
+ }
823
+ if (running && (old.id || old.status === 4))
824
+ return;
825
+ if (old.id && old.source !== 'legacy')
826
+ return;
827
+ }
828
+ let identity;
829
+ if (!old) {
830
+ const [prior] = await this.database.query('SELECT 1 FROM CronTriggers WHERE id=$receipt UNION ALL SELECT 1 FROM CronHistoryRetention WHERE cutoff>$start', { transaction, type: sequelize_1.QueryTypes.SELECT, bind: { receipt, start } });
831
+ if (prior)
832
+ return;
833
+ identity = (0, cronProcess_1.legacyProcessOwner)(pid, seconds);
834
+ const roots = await this.database.query(`SELECT id,command_identity FROM CronTriggers WHERE cron_id=$cronId AND state='running'
835
+ AND command_identity IS NOT NULL AND started_at < $end`, { transaction, type: sequelize_1.QueryTypes.SELECT, bind: { cronId, end: start + 1000 } });
836
+ for (const root of roots) {
837
+ if (!identity)
838
+ break;
839
+ const parent = Number(root.command_identity.split(':')[1]);
840
+ try {
841
+ if (!(0, cronProcess_1.isProcessDescendant)(pid, parent) || (0, cronProcess_1.systemOwner)(parent) !== root.command_identity)
842
+ continue;
843
+ }
844
+ catch (error) {
845
+ if (['ENOENT', 'ESRCH'].includes(error.code))
846
+ continue;
847
+ throw error;
848
+ }
849
+ await this.database.query('INSERT INTO CronShellBindings(receipt,trigger_id) VALUES ($receipt,$id)', { transaction, bind: { receipt, id: root.id } });
850
+ if (running)
851
+ await this.attachShellLog(root.id, cronId, log, transaction);
852
+ return;
853
+ }
854
+ }
855
+ const id = (_b = old === null || old === void 0 ? void 0 : old.id) !== null && _b !== void 0 ? _b : receipt;
856
+ if (!(old === null || old === void 0 ? void 0 : old.id)) {
857
+ // A later use of the same numeric PID proves the older process is gone.
858
+ const others = await this.database.query(`SELECT t.id,i.started_at FROM RunningInstances i LEFT JOIN CronTriggers t ON t.instance_id=i.id
859
+ WHERE i.cron_id=$cronId AND i.pid=$pid AND i.started_at<>$seconds
860
+ AND (i.started_at>$seconds OR (i.status=0 AND t.source='legacy'))`, { transaction, type: sequelize_1.QueryTypes.SELECT, bind: { cronId, pid, seconds } });
861
+ if (running && old)
862
+ identity = (0, cronProcess_1.legacyProcessOwner)(pid, seconds);
863
+ const historical = !running || !identity || others.some(other => other.started_at > seconds);
864
+ let instance = old === null || old === void 0 ? void 0 : old.instance;
865
+ if (!instance) {
866
+ [instance] = await this.database.query(`INSERT INTO RunningInstances(cron_id,pid,log_path,started_at,status,finished_at,createdAt,updatedAt)
867
+ VALUES ($cronId,$pid,$log,$seconds,$status,$finished,CURRENT_TIMESTAMP,CURRENT_TIMESTAMP)`, { transaction, type: sequelize_1.QueryTypes.INSERT, bind: { cronId, pid, log: log || null, seconds,
868
+ status: historical ? 4 : 0, finished: historical ? Math.floor(Date.now() / 1000) : null } });
869
+ }
870
+ const unknown = historical || (old === null || old === void 0 ? void 0 : old.status) === 4;
871
+ await this.database.query(`INSERT INTO CronTriggers
872
+ (id,cron_id,source,state,observed_at,started_at,finished_at,instance_id,log_path,process_identity,reason)
873
+ VALUES ($id,$cronId,'legacy',$state,$start,$start,$end,$instance,$log,$identity,$reason)`, { transaction, bind: { id, cronId, start, instance, log: (_c = old === null || old === void 0 ? void 0 : old.log_path) !== null && _c !== void 0 ? _c : (log || null), identity: !unknown && running ? identity !== null && identity !== void 0 ? identity : null : null,
874
+ reason: old && running && !unknown ? 'restart' : null,
875
+ state: unknown ? 'unknown' : 'running', end: unknown ? ((old === null || old === void 0 ? void 0 : old.finished_at) ? old.finished_at * 1000 : Date.now()) : null } });
876
+ await this.claimSummary(cronId, instance, seconds, transaction, (old === null || old === void 0 ? void 0 : old.status) === 0 || (running && !unknown));
877
+ for (const other of others) {
878
+ if (other.started_at < seconds)
879
+ await this.completeInTransaction(other.id, 'unknown', null, null, transaction);
880
+ }
881
+ if (running && !unknown)
882
+ await this.database.query(`UPDATE Crontabs SET status=0,pid=$pid,log_path=$log
883
+ WHERE id=$cronId AND status IS NOT 3 AND $instance=(
884
+ SELECT id FROM RunningInstances WHERE cron_id=$cronId AND status=0 ORDER BY id DESC LIMIT 1)`, { transaction, bind: { cronId, pid, log: log || null, instance } });
885
+ if (unknown && (old === null || old === void 0 ? void 0 : old.status) === 0 && running)
886
+ await this.settleInstance(id, transaction);
887
+ }
888
+ if (!running) {
889
+ const state = code == null ? 'unknown' : code === 0 ? 'finished' : 'failed';
890
+ await this.completeInTransaction(id, state, null, code !== null && code !== void 0 ? code : null, transaction, Math.max(0, elapsed) * 1000);
891
+ }
892
+ }
893
+ async attachShellLog(id, cronId, log, transaction) {
894
+ const attached = await this.database.query(`UPDATE RunningInstances SET log_path=$log WHERE status=0 AND log_path IS NULL
895
+ AND id=(SELECT instance_id FROM CronTriggers WHERE id=$id AND cron_id=$cronId AND state='running')`, { transaction, type: sequelize_1.QueryTypes.BULKUPDATE, bind: { id, cronId, log } });
896
+ if (attached) {
897
+ await this.database.query('UPDATE CronTriggers SET log_path=COALESCE(log_path,$log) WHERE id=$id', { transaction, bind: { id, log } });
898
+ await this.database.query(`UPDATE Crontabs SET log_path=$log WHERE id=$cronId AND status=0 AND pid=(
899
+ SELECT i.pid FROM RunningInstances i JOIN CronTriggers t ON t.instance_id=i.id WHERE t.id=$id)`, { transaction, bind: { id, cronId, log } });
900
+ }
901
+ }
902
+ // Link the Shell instance and its trigger in the same IMMEDIATE write transaction.
903
+ async reportInstance(id, cronId, running, pid, log, seconds, elapsed, code, stopped = false, finishedAt) {
904
+ const sample = running ? undefined : await this.readScriptSample(id);
905
+ await this.database.transaction(async (transaction) => {
906
+ var _a;
907
+ const accepted = await this.shellReport(id, cronId, id.startsWith('system-'), running, log, seconds, code, stopped, transaction, elapsed == null ? undefined : elapsed * 1000, finishedAt);
908
+ if (accepted === false)
909
+ return;
910
+ const [row] = await this.database.query('SELECT state,started_at,instance_id,command_identity,owner FROM CronTriggers WHERE id=$id AND cron_id=$cronId', { transaction, bind: { id, cronId }, type: sequelize_1.QueryTypes.SELECT });
911
+ if (!row)
912
+ return;
913
+ const startSeconds = seconds > 0 ? seconds : Math.floor(((_a = row.started_at) !== null && _a !== void 0 ? _a : Date.now()) / 1000);
914
+ if (['finished', 'failed', 'stopped', 'unknown'].includes(row.state) && row.owner === null && row.instance_id === null) {
915
+ // The CLI exit can commit before its first start. Link a terminal history
916
+ // row directly without ever publishing this PID as the current instance.
917
+ const [instance] = await this.database.query(`INSERT INTO RunningInstances
918
+ (cron_id,pid,log_path,started_at,finished_at,status,exit_code,createdAt,updatedAt)
919
+ SELECT cron_id,$pid,log_path,CAST(started_at/1000 AS INTEGER),CAST(finished_at/1000 AS INTEGER),
920
+ CASE state WHEN 'finished' THEN 1 WHEN 'stopped' THEN 2 WHEN 'failed' THEN 3 ELSE 4 END,
921
+ exit_code,CURRENT_TIMESTAMP,CURRENT_TIMESTAMP FROM CronTriggers
922
+ WHERE id=$id AND state IN ('finished','failed','stopped','unknown')`, { transaction, type: sequelize_1.QueryTypes.INSERT, bind: { id, pid: pid || null } });
923
+ if (instance) {
924
+ await this.database.query('UPDATE CronTriggers SET instance_id=$instance WHERE id=$id', { transaction, bind: { instance, id } });
925
+ await this.claimSummary(cronId, instance, startSeconds, transaction, false, row.state === 'unknown' ? null : elapsed !== null && elapsed !== void 0 ? elapsed : null);
926
+ }
927
+ return;
928
+ }
929
+ if (running && row.state !== 'running')
930
+ return;
931
+ if (running && row.instance_id === null) {
932
+ let identity = row.command_identity;
933
+ if (identity === null || identity === void 0 ? void 0 : identity.startsWith('crond:')) {
934
+ pid = Number(identity.split(':')[1]);
935
+ }
936
+ else if (pid) {
937
+ try {
938
+ identity = (0, cronProcess_1.systemOwner)(pid);
939
+ }
940
+ catch ( /* A short child may have exited. */_b) { /* A short child may have exited. */ }
941
+ }
942
+ const [instance] = await this.database.query(`INSERT INTO RunningInstances(cron_id,pid,log_path,started_at,status,createdAt,updatedAt)
943
+ VALUES ($cronId,$pid,$log,$seconds,0,CURRENT_TIMESTAMP,CURRENT_TIMESTAMP)`, { transaction, type: sequelize_1.QueryTypes.INSERT, bind: { cronId, pid, log, seconds: startSeconds } });
944
+ await this.database.query('UPDATE CronTriggers SET instance_id=$instance,process_identity=$identity WHERE id=$id', { transaction, bind: { instance, identity, id } });
945
+ await this.claimSummary(cronId, instance, startSeconds, transaction, true);
946
+ await this.database.query(`UPDATE Crontabs SET status=0,pid=$pid,log_path=$log
947
+ WHERE id=$cronId AND (status IS NOT 3 OR queued_token || '-' || id=$id)`, { transaction, bind: { cronId, id, pid, log } });
948
+ }
949
+ if (running && row.instance_id !== null) {
950
+ await this.attachShellLog(id, cronId, log, transaction);
951
+ }
952
+ if (!running)
953
+ await this.saveScriptSample(id, sample, transaction);
954
+ });
955
+ }
956
+ async settleInstance(id, transaction) {
957
+ const [row] = await this.database.query(`SELECT cron_id,instance_id,log_path,state,finished_at,exit_code FROM CronTriggers
958
+ WHERE id=$id AND instance_id IS NOT NULL AND finished_at IS NOT NULL`, { transaction, bind: { id }, type: sequelize_1.QueryTypes.SELECT });
959
+ if (!row)
960
+ return;
961
+ if (row.state === 'skipped') {
962
+ // The launch gate closed before user code ran.
963
+ await this.database.query('DELETE FROM RunningInstances WHERE id=$instance AND status=0', { transaction, bind: { instance: row.instance_id } });
964
+ await this.database.query('UPDATE CronTriggers SET instance_id=NULL WHERE id=$id', { transaction, bind: { id } });
965
+ }
966
+ else {
967
+ const status = row.state === 'finished' ? 1 : row.state === 'stopped' ? 2 : row.state === 'unknown' ? 4 : 3;
968
+ const updated = await this.database.query(`UPDATE RunningInstances SET status=$status,finished_at=$end,exit_code=$code,
969
+ updatedAt=CURRENT_TIMESTAMP WHERE id=$instance AND cron_id=$cronId AND status=0`, { transaction, type: sequelize_1.QueryTypes.BULKUPDATE, bind: { instance: row.instance_id, cronId: row.cron_id,
970
+ status, end: Math.floor(row.finished_at / 1000), code: row.exit_code } });
971
+ if (!updated) {
972
+ // A late exit corrects only the historical instance. Its replacement
973
+ // already owns the task row, even when it uses the same PID and log.
974
+ if (status !== 4)
975
+ await this.database.query(`UPDATE RunningInstances
976
+ SET status=$status,finished_at=$end,exit_code=$code,updatedAt=CURRENT_TIMESTAMP
977
+ WHERE id=$instance AND cron_id=$cronId AND status=4`, { transaction, bind: { instance: row.instance_id, cronId: row.cron_id, status,
978
+ end: Math.floor(row.finished_at / 1000), code: row.exit_code } });
979
+ return;
980
+ }
981
+ }
982
+ // A newer manual reservation owns its own token. Never clear it while an older run exits.
983
+ const [active] = await this.database.query('SELECT pid,log_path,started_at FROM RunningInstances WHERE cron_id=$cronId AND status=0 ORDER BY id DESC LIMIT 1', { transaction, bind: { cronId: row.cron_id }, type: sequelize_1.QueryTypes.SELECT });
984
+ if (active) {
985
+ await this.database.query(`UPDATE Crontabs SET status=0,pid=$pid,log_path=$log
986
+ WHERE id=$cronId AND status IS NOT 3`, { transaction, bind: { cronId: row.cron_id,
987
+ pid: active.pid, log: active.log_path } });
988
+ }
989
+ else {
990
+ await this.database.query(`UPDATE Crontabs SET status=1,pid=NULL,queued_token=NULL
991
+ WHERE id=$cronId AND status=0 AND log_path IS $log`, { transaction, bind: { cronId: row.cron_id, log: row.log_path } });
992
+ }
993
+ }
994
+ async cancelQueued(ids) {
995
+ if (!ids.length)
996
+ return [];
997
+ return this.database.transaction(tx => this.cancelQueuedInTransaction(ids, tx));
998
+ }
999
+ async cancelQueuedInTransaction(ids, transaction) {
1000
+ await this.database.query("UPDATE CronTriggers SET stop_requested=1 WHERE cron_id IN (:ids) AND state='running' AND command_identity IS NULL AND instance_id IS NULL", { replacements: { ids }, transaction });
1001
+ const rows = await this.database.query("SELECT id FROM CronTriggers WHERE cron_id IN (:ids) AND state='queued'", { replacements: { ids }, transaction, type: sequelize_1.QueryTypes.SELECT });
1002
+ await this.database.query(`UPDATE CronTriggers SET state='stopped',reason='cancelled',finished_at=:now
1003
+ WHERE cron_id IN (:ids) AND state='queued'`, { replacements: { ids, now: Date.now() }, transaction });
1004
+ return rows.map((r) => r.id);
1005
+ }
1006
+ async queueInstanceStop(instanceId, cronId, pid, transaction, identity) {
1007
+ await this.database.query(`INSERT INTO CronStopRequests(instance_id,cron_id,pid,root_identity,namespace_owner)
1008
+ VALUES ($instanceId,$cronId,$pid,$identity,$namespace)
1009
+ ON CONFLICT(instance_id) DO UPDATE SET root_identity=excluded.root_identity
1010
+ WHERE root_identity IS NULL AND excluded.root_identity IS NOT NULL AND pid=excluded.pid AND signalled=0`, { transaction, bind: { instanceId, cronId, pid, identity: identity !== null && identity !== void 0 ? identity : null, namespace: (0, cronProcess_1.pidNamespaceOwner)() } });
1011
+ }
1012
+ async pendingStop(instanceId, transaction) {
1013
+ const [row] = await this.database.query('SELECT targets,signalled,signalled_at,root_identity,namespace_owner FROM CronStopRequests WHERE instance_id=$instanceId', { transaction, bind: { instanceId }, type: sequelize_1.QueryTypes.SELECT });
1014
+ return row;
1015
+ }
1016
+ async pendingStopBatches() {
1017
+ return this.database.query('SELECT request_id,cron_ids FROM CronStopBatches WHERE snapshot IS NOT NULL', { type: sequelize_1.QueryTypes.SELECT });
1018
+ }
1019
+ async pendingStops() {
1020
+ return this.database.query('SELECT instance_id,cron_id,pid,targets FROM CronStopRequests ORDER BY instance_id', { type: sequelize_1.QueryTypes.SELECT });
1021
+ }
1022
+ async forgetStop(instanceId, onEnded) {
1023
+ return this.database.transaction(async (transaction) => {
1024
+ await this.database.query('DELETE FROM CronStopRequests WHERE instance_id=$instanceId AND signalled=0', { transaction, bind: { instanceId } });
1025
+ const claimed = await this.pendingStop(instanceId, transaction);
1026
+ if (!claimed && onEnded)
1027
+ await onEnded(transaction);
1028
+ return claimed;
1029
+ });
1030
+ }
1031
+ async shouldStop(id, transaction) {
1032
+ const rows = await this.database.query("SELECT 1 FROM CronTriggers WHERE id=$id AND stop_requested=1", { transaction, bind: { id }, type: sequelize_1.QueryTypes.SELECT });
1033
+ return rows.length > 0;
1034
+ }
1035
+ // The outer command can outlive any of its task wrappers.
1036
+ async recordCommandStart(id, at) {
1037
+ await this.database.query(`UPDATE CronTriggers SET command_started_at=$at
1038
+ WHERE id=$id AND command_started_at IS NULL AND started_at IS NOT NULL`, { bind: { id, at } });
1039
+ }
1040
+ async bindCommand(id, pid, log) {
1041
+ let identity;
1042
+ try {
1043
+ identity = (0, cronProcess_1.systemOwner)(pid);
1044
+ }
1045
+ catch (error) {
1046
+ if (['ESRCH', 'ENOENT'].includes(error.code))
1047
+ return false;
1048
+ throw error;
1049
+ }
1050
+ return this.database.transaction(async (transaction) => {
1051
+ const [row] = await this.database.query("SELECT instance_id,cron_id,started_at FROM CronTriggers WHERE id=$id AND state='running'", { transaction, bind: { id }, type: sequelize_1.QueryTypes.SELECT });
1052
+ if (!row)
1053
+ return false;
1054
+ await this.database.query('UPDATE CronTriggers SET command_identity=$identity WHERE id=$id', { transaction, bind: { identity, id } });
1055
+ if (row.instance_id) {
1056
+ await this.database.query('UPDATE RunningInstances SET pid=$pid WHERE id=$instance AND status=0', { transaction, bind: { pid, instance: row.instance_id } });
1057
+ await this.database.query('UPDATE CronTriggers SET process_identity=$identity WHERE id=$id', { transaction, bind: { identity, id } });
1058
+ await this.database.query('UPDATE Crontabs SET pid=$pid WHERE id=$cronId AND log_path=(SELECT log_path FROM CronTriggers WHERE id=$id) AND status=0', { transaction, bind: { pid, cronId: row.cron_id, id } });
1059
+ }
1060
+ else {
1061
+ await this.registerCommandInstance(id, row.cron_id, pid, identity, row.started_at, log, transaction);
1062
+ }
1063
+ return true;
1064
+ });
1065
+ }
1066
+ async registerCommandInstance(id, cronId, pid, identity, started, log, transaction) {
1067
+ const seconds = Math.floor(started / 1000);
1068
+ const [instance] = await this.database.query(`INSERT INTO RunningInstances(cron_id,pid,log_path,started_at,status,createdAt,updatedAt)
1069
+ VALUES ($cronId,$pid,$log,$seconds,0,CURRENT_TIMESTAMP,CURRENT_TIMESTAMP)`, { transaction, type: sequelize_1.QueryTypes.INSERT, bind: { cronId, pid, log: log !== null && log !== void 0 ? log : null, seconds } });
1070
+ await this.database.query('UPDATE CronTriggers SET log_path=$log,instance_id=$instance,process_identity=$identity WHERE id=$id', { transaction, bind: { id, log: log !== null && log !== void 0 ? log : null, instance, identity } });
1071
+ await this.claimSummary(cronId, instance, seconds, transaction, true);
1072
+ if (log === undefined)
1073
+ await this.database.query('UPDATE Crontabs SET status=0,pid=$pid,log_path=NULL WHERE id=$cronId AND status IS NOT 3', { transaction, bind: { cronId, pid } });
1074
+ }
1075
+ async activeCommands(ids, transaction) {
1076
+ if (!ids.length)
1077
+ return [];
1078
+ return this.database.query("SELECT id,cron_id,command_identity,started_at,log_path FROM CronTriggers WHERE cron_id IN (:ids) AND state='running' AND instance_id IS NULL AND command_identity IS NOT NULL", { replacements: { ids }, transaction, type: sequelize_1.QueryTypes.SELECT });
1079
+ }
1080
+ async instanceIdentity(instanceId) {
1081
+ const [row] = await this.database.query('SELECT process_identity FROM CronTriggers WHERE instance_id=$instanceId', { bind: { instanceId }, type: sequelize_1.QueryTypes.SELECT });
1082
+ return row === null || row === void 0 ? void 0 : row.process_identity;
1083
+ }
1084
+ async requestInstanceStop(instanceId, pid, signalTree, targets) {
1085
+ // Commit the verified tree BEFORE the first signal. If this worker dies even
1086
+ // inside the following transaction, its replacement still has the original PIDs.
1087
+ if (targets)
1088
+ await this.database.query(`INSERT INTO CronStopRequests(instance_id,cron_id,pid,targets)
1089
+ SELECT i.id,i.cron_id,i.pid,$targets FROM RunningInstances i WHERE i.id=$instanceId AND i.pid=$pid AND i.status=0
1090
+ ON CONFLICT(instance_id) DO UPDATE SET targets=(
1091
+ SELECT json_group_array(value) FROM (SELECT value FROM json_each(CronStopRequests.targets)
1092
+ UNION SELECT value FROM json_each(excluded.targets))) WHERE CronStopRequests.signalled=0`, { bind: { instanceId, pid, targets: JSON.stringify(targets) } });
1093
+ const result = await this.database.transaction({ type: sequelize_1.Transaction.TYPES.IMMEDIATE }, async (transaction) => {
1094
+ const [row] = await this.database.query(`SELECT t.id,i.pid,i.status,t.state,t.stop_requested FROM RunningInstances i
1095
+ LEFT JOIN CronTriggers t ON t.instance_id=i.id WHERE i.id=$instanceId`, { transaction, bind: { instanceId }, type: sequelize_1.QueryTypes.SELECT });
1096
+ if (!row || row.status !== 0 || (row.state && row.state !== 'running')) {
1097
+ throw Object.assign(new Error('Instance already ended'), { code: 'ESRCH' });
1098
+ }
1099
+ if (row.pid !== pid)
1100
+ throw Object.assign(new Error('Instance process changed'), { status: 409 });
1101
+ if (row.stop_requested && !targets)
1102
+ return;
1103
+ const existing = await this.pendingStop(instanceId, transaction);
1104
+ const savedTargets = (existing === null || existing === void 0 ? void 0 : existing.targets) ? JSON.parse(existing.targets) : [];
1105
+ if (existing === null || existing === void 0 ? void 0 : existing.signalled)
1106
+ return { targets: savedTargets, signalledAt: existing.signalled_at };
1107
+ // The supervisor can still be draining output after the command has exited.
1108
+ if (row.id) {
1109
+ const exit = await this.exitBeforeStop(row.id);
1110
+ // An I/O error alone cannot prove a live process has already exited.
1111
+ if (!exit.published && exit.unreadable)
1112
+ throw Object.assign(new Error('Cannot verify command exit. Retry the stop request.'), { status: 503 });
1113
+ if (exit.published) {
1114
+ await this.completeCommandExit(row.id, 'unknown', null, null, transaction, exit.canonical, undefined, undefined, exit.recovered);
1115
+ return { ended: true };
1116
+ }
1117
+ }
1118
+ if (targets && !(existing === null || existing === void 0 ? void 0 : existing.targets)) {
1119
+ // Another worker released the prepared tree. Retry from a durable
1120
+ // snapshot before issuing an irreversible signal.
1121
+ throw Object.assign(new Error('Stop target snapshot changed. Retry the stop request.'), { status: 503 });
1122
+ }
1123
+ const signalledAt = Date.now();
1124
+ await this.database.query('UPDATE CronStopRequests SET signalled=1,signalled_at=$signalledAt WHERE instance_id=$instanceId', { transaction, bind: { instanceId, signalledAt } });
1125
+ if (row.state)
1126
+ await this.database.query("UPDATE CronTriggers SET stop_requested=1 WHERE instance_id=$instanceId AND state='running'", { bind: { instanceId }, transaction });
1127
+ // Root delivery failure rolls back. After successful root delivery, retain
1128
+ // the stop marker even if some descendants still need recovery.
1129
+ const error = signalTree();
1130
+ return { targets: savedTargets, signalledAt, error };
1131
+ });
1132
+ if (result && 'ended' in result)
1133
+ throw Object.assign(new Error('Instance already ended'), { code: 'ESRCH' });
1134
+ if (result && 'error' in result && result.error instanceof Error)
1135
+ throw result.error;
1136
+ if (targets && result)
1137
+ return { targets: result.targets, signalledAt: result.signalledAt };
1138
+ }
1139
+ async exitBeforeStop(id) {
1140
+ const recovered = await Promise.all((await (0, managedExit_cjs_1.retiringExits)()).filter(copy => copy.id === id)
1141
+ .map(copy => (0, managedExit_cjs_1.readExit)(id, copy.file)));
1142
+ const canonical = await (0, managedExit_cjs_1.readExit)(id);
1143
+ const verified = recovered.some(copy => (copy === null || copy === void 0 ? void 0 : copy.version) === 1);
1144
+ const unreadable = canonical === null || recovered.some(copy => copy === null ||
1145
+ (copy && copy.version !== 1 && isBoundPublication(copy.file)));
1146
+ return { canonical, recovered, published: Boolean(canonical || verified), unreadable };
1147
+ }
1148
+ async instanceStopRequested(instanceId, transaction) {
1149
+ const [row] = await this.database.query('SELECT stop_requested FROM CronTriggers WHERE instance_id=$instanceId', { transaction, bind: { instanceId }, type: sequelize_1.QueryTypes.SELECT });
1150
+ return row && Boolean(row.stop_requested);
1151
+ }
1152
+ async stopVerifiedInstance(instanceId, settleLegacy) {
1153
+ return this.database.transaction(async (transaction) => {
1154
+ var _a, _b;
1155
+ const [row] = await this.database.query('SELECT id,owner,command_identity,reason,state,stop_exit_at,exit_code,exit_pending FROM CronTriggers WHERE instance_id=$instanceId', { transaction, bind: { instanceId }, type: sequelize_1.QueryTypes.SELECT });
1156
+ await this.database.query('DELETE FROM CronStopRequests WHERE instance_id=$instanceId', { transaction, bind: { instanceId } });
1157
+ if (!row)
1158
+ return settleLegacy ? settleLegacy(transaction) : false;
1159
+ if (row.state !== 'running')
1160
+ return row.state === 'stopped';
1161
+ const legacyCrond = ((_a = row.owner) === null || _a === void 0 ? void 0 : _a.startsWith('crond:')) && (!row.command_identity || row.owner === row.command_identity);
1162
+ // A live scheduler drains its log and reports the actual exit. If the
1163
+ // callback already arrived or its owner is gone, settle in this transaction.
1164
+ const exit = await this.exitBeforeStop(row.id);
1165
+ if (exit.published || exit.unreadable || row.exit_pending || row.stop_exit_at !== null || !row.owner || legacyCrond || row.reason === 'restart') {
1166
+ await this.recoverScriptSample(row.id, transaction);
1167
+ await this.completeCommandExit(row.id, 'stopped', 'cancelled', row.exit_code, transaction, exit.canonical, (_b = row.stop_exit_at) !== null && _b !== void 0 ? _b : undefined, undefined, exit.recovered);
1168
+ }
1169
+ return true;
1170
+ });
1171
+ }
1172
+ async queueCounts() {
1173
+ await this.recoverSystemOwners();
1174
+ const [row] = await this.database.query("SELECT COUNT(*) AS triggers, COUNT(DISTINCT cron_id) AS tasks FROM CronTriggers WHERE state='queued' AND dequeued_at IS NULL", { type: sequelize_1.QueryTypes.SELECT });
1175
+ return row;
1176
+ }
1177
+ async startSystem(id, cronId, owner, commandIdentity = owner, wrapper) {
1178
+ // crond only tells us when the wrapper starts. It supplies no scheduled or queued time.
1179
+ return this.database.transaction(async (transaction) => {
1180
+ var _a, _b, _c;
1181
+ const [task] = await this.database.query('SELECT allow_multiple_instances, status, pid, isDisabled FROM Crontabs WHERE id=$cronId', { bind: { cronId }, type: sequelize_1.QueryTypes.SELECT, transaction });
1182
+ if (!task || (task.isDisabled && !(wrapper === null || wrapper === void 0 ? void 0 : wrapper.dispatch)))
1183
+ return false;
1184
+ const now = Date.now();
1185
+ const inserted = await this.database.query(`INSERT INTO CronTriggers(id,cron_id,source,state,owner,command_identity,observed_at,system_rule,system_dispatch_at)
1186
+ VALUES ($id,$cronId,'system','queued',$owner,$commandIdentity,$observed,$rule,$dispatch) ON CONFLICT(id) DO NOTHING`, { bind: { id, cronId, owner, commandIdentity, observed: (_a = wrapper === null || wrapper === void 0 ? void 0 : wrapper.at) !== null && _a !== void 0 ? _a : now, rule: (_b = wrapper === null || wrapper === void 0 ? void 0 : wrapper.rule) !== null && _b !== void 0 ? _b : null, dispatch: (_c = wrapper === null || wrapper === void 0 ? void 0 : wrapper.dispatch) !== null && _c !== void 0 ? _c : null }, type: sequelize_1.QueryTypes.BULKUPDATE, transaction });
1187
+ if (!inserted)
1188
+ return false;
1189
+ if (task.isDisabled) {
1190
+ await this.finish(id, 'skipped', 'changed', null, transaction);
1191
+ return false;
1192
+ }
1193
+ const multiple = task.allow_multiple_instances === 1;
1194
+ const claimed = (multiple || !(0, cronProcess_1.hasLiveCronProcess)(task.status, task.pid))
1195
+ && await this.start(id, now, multiple, transaction);
1196
+ if (claimed && wrapper)
1197
+ await this.database.query('UPDATE CronTriggers SET command_started_at=$now WHERE id=$id', { transaction, bind: { id, now } });
1198
+ if (claimed && owner.startsWith('crond:')) {
1199
+ await this.registerCommandInstance(id, cronId, Number(commandIdentity.split(':')[1]), commandIdentity, now, undefined, transaction);
1200
+ }
1201
+ if (!claimed)
1202
+ await this.finish(id, 'skipped', 'overlap', null, transaction);
1203
+ return claimed;
1204
+ });
1205
+ }
1206
+ async recoverSystemOwners(cronId, transaction, instanceId) {
1207
+ // HTTP may restart while crond children keep running. Match process birth, including across reboots.
1208
+ const active = await this.database.query(`SELECT id,CASE WHEN owner LIKE 'crond:%' THEN owner ELSE COALESCE(command_identity,process_identity) END AS owner FROM CronTriggers WHERE state='running' AND (owner LIKE 'crond:%' OR reason='restart')
1209
+ AND NOT EXISTS (SELECT 1 FROM CronStopRequests s WHERE s.instance_id=CronTriggers.instance_id AND s.targets IS NOT NULL)
1210
+ AND ($cronId IS NULL OR cron_id=$cronId) AND ($instanceId IS NULL OR instance_id=$instanceId)`, { transaction, bind: { cronId: cronId !== null && cronId !== void 0 ? cronId : null, instanceId: instanceId !== null && instanceId !== void 0 ? instanceId : null }, type: sequelize_1.QueryTypes.SELECT });
1211
+ let reclaimed = false;
1212
+ for (const row of active) {
1213
+ const pid = Number(row.owner.split(':')[1]);
1214
+ try {
1215
+ if ((0, cronProcess_1.systemOwner)(pid) === row.owner)
1216
+ continue;
1217
+ }
1218
+ catch (error) {
1219
+ const code = error.code;
1220
+ if (code !== 'ENOENT' && code !== 'ESRCH')
1221
+ throw error;
1222
+ }
1223
+ const close = async (tx) => {
1224
+ var _a;
1225
+ const [current] = await this.database.query(`SELECT stop_requested,exit_code,stop_exit_at FROM CronTriggers WHERE id=$id AND state='running'
1226
+ AND NOT EXISTS (SELECT 1 FROM CronStopRequests s WHERE s.instance_id=CronTriggers.instance_id AND s.targets IS NOT NULL)`, { transaction: tx, bind: { id: row.id }, type: sequelize_1.QueryTypes.SELECT });
1227
+ if (!current)
1228
+ return;
1229
+ await this.recoverScriptSample(row.id, tx);
1230
+ await this.completeCommandExit(row.id, current.stop_requested ? 'stopped' : 'unknown', current.stop_requested ? 'cancelled' : 'restart', current.exit_code, tx, undefined, (_a = current.stop_exit_at) !== null && _a !== void 0 ? _a : undefined);
1231
+ };
1232
+ if (transaction)
1233
+ await close(transaction);
1234
+ else
1235
+ await this.database.transaction(close);
1236
+ reclaimed = true;
1237
+ }
1238
+ return reclaimed;
1239
+ }
1240
+ async interrupt(owner) {
1241
+ await this.database.transaction(async (transaction) => {
1242
+ await this.replayPublishedExits(transaction);
1243
+ if (owner === 'http')
1244
+ await this.database.query(`INSERT OR IGNORE INTO CronStopRequests(instance_id,cron_id,pid)
1245
+ SELECT instance_id,cron_id,CAST(substr(process_identity,7) AS INTEGER) FROM CronTriggers
1246
+ WHERE state='running' AND stop_requested=1 AND instance_id IS NOT NULL AND process_identity LIKE 'crond:%'`, { transaction });
1247
+ // No process was bound and its launch gate closed when the worker exited.
1248
+ await this.database.query(`UPDATE CronTriggers SET state='stopped',reason='cancelled',started_at=NULL,finished_at=$now
1249
+ WHERE owner=$owner AND state='running' AND stop_requested=1 AND instance_id IS NULL AND command_identity IS NULL`, { transaction, bind: { owner, now: Date.now() } });
1250
+ await this.database.query(`UPDATE CronTriggers SET reason='restart',
1251
+ state=CASE WHEN state='queued' THEN 'skipped' WHEN COALESCE(command_identity,process_identity) IS NOT NULL THEN 'running' ELSE 'unknown' END,
1252
+ finished_at=CASE WHEN state='running' AND COALESCE(command_identity,process_identity) IS NOT NULL THEN NULL ELSE $now END
1253
+ WHERE (owner=$owner OR (source IN ('system','legacy','client') AND owner IS NULL AND $owner='http')) AND state IN ('queued','running')`, { transaction, bind: { owner, now: Date.now() } });
1254
+ await this.recoverSystemOwners(undefined, transaction);
1255
+ });
1256
+ }
1257
+ async reconcileInstances() {
1258
+ await this.database.transaction(async (transaction) => {
1259
+ // Released panels created instance rows before trigger IDs existed. Link
1260
+ // their outstanding starts before cleanup so the original CLI can finish.
1261
+ const unlinked = await this.database.query(`WITH outstanding AS (SELECT DISTINCT cron_id,started_at FROM RunningInstances WHERE status=0)
1262
+ SELECT i.cron_id,i.pid,i.log_path,i.started_at FROM outstanding o
1263
+ JOIN RunningInstances i ON i.cron_id=o.cron_id AND i.started_at=o.started_at
1264
+ JOIN Crontabs c ON c.id=i.cron_id WHERE i.pid>0 AND i.started_at>0
1265
+ AND NOT EXISTS (SELECT 1 FROM CronTriggers t WHERE t.instance_id=i.id)
1266
+ AND NOT EXISTS (SELECT 1 FROM CronStopRequests s WHERE s.instance_id=i.id)
1267
+ ORDER BY i.started_at,i.id`, { transaction, type: sequelize_1.QueryTypes.SELECT });
1268
+ for (const row of unlinked) {
1269
+ await this.applyLegacyReceipt(row.cron_id, true, row.pid, row.log_path || '', row.started_at, 0, transaction);
1270
+ }
1271
+ // Older versions mapped an unknown exit to error or stopped in instance history.
1272
+ await this.database.query(`UPDATE RunningInstances SET status=4,finished_at=COALESCE(finished_at,$now),updatedAt=CURRENT_TIMESTAMP
1273
+ WHERE status IN (0,2,3) AND id IN
1274
+ (SELECT instance_id FROM CronTriggers WHERE state='unknown' AND instance_id IS NOT NULL)`, { transaction, bind: { now: Math.floor(Date.now() / 1000) } });
1275
+ // HTTP and gRPC restart independently. Another worker or crond may still own the run.
1276
+ await this.database.query(`UPDATE RunningInstances SET status=2,finished_at=$now,updatedAt=CURRENT_TIMESTAMP
1277
+ WHERE status=0 AND NOT EXISTS (SELECT 1 FROM CronStopRequests s WHERE s.instance_id=RunningInstances.id)
1278
+ AND NOT EXISTS (SELECT 1 FROM CronTriggers t WHERE t.instance_id=RunningInstances.id AND t.state='running')`, { transaction, bind: { now: Math.floor(Date.now() / 1000) } });
1279
+ await this.database.query(`UPDATE Crontabs SET status=1,pid=NULL,queued_token=NULL
1280
+ WHERE status IN (0,3) AND NOT EXISTS (SELECT 1 FROM CronStopRequests s WHERE s.cron_id=Crontabs.id)
1281
+ AND NOT EXISTS (SELECT 1 FROM CronTriggers t
1282
+ WHERE t.cron_id=Crontabs.id AND t.state IN ('running','queued'))`, { transaction });
1283
+ });
1284
+ }
1285
+ async countExpired(cutoff) {
1286
+ const [row] = await this.database.query(`SELECT COUNT(*) AS count FROM CronTriggers WHERE ${TriggerHistory.expired}`, { bind: { cutoff }, type: sequelize_1.QueryTypes.SELECT });
1287
+ return row.count;
1288
+ }
1289
+ async deleteExpired(cutoff, transaction) {
1290
+ // Once both histories have expired, old packets must not recreate their rows.
1291
+ await this.database.query(`INSERT INTO CronHistoryRetention(id,cutoff) VALUES (1,$cutoff)
1292
+ ON CONFLICT(id) DO UPDATE SET cutoff=MAX(cutoff,excluded.cutoff)`, { transaction, bind: { cutoff } });
1293
+ // The visible histories can expire before statistics. Keep just enough to
1294
+ // credit a verified receipt to its task without recreating either history.
1295
+ await this.database.query(`INSERT OR IGNORE INTO CronPrunedUnknownRuns(trigger_id,cron_id,source,started_at,last_possible_day)
1296
+ SELECT id,cron_id,source,started_at,date(finished_at/1000,'unixepoch','localtime') FROM CronTriggers
1297
+ WHERE ${TriggerHistory.expired} AND state='unknown' AND reason='restart' AND counted=0 AND owner IS NOT NULL
1298
+ AND started_at IS NOT NULL AND EXISTS (SELECT 1 FROM Crontabs WHERE id=CronTriggers.cron_id)
1299
+ AND NOT EXISTS (SELECT 1 FROM CronLegacyExitBookings WHERE trigger_id=CronTriggers.id)
1300
+ AND NOT EXISTS (SELECT 1 FROM CronStatRetention WHERE first_day>date(finished_at/1000,'unixepoch','localtime'))`, { bind: { cutoff }, transaction });
1301
+ return this.database.query(`DELETE FROM CronTriggers WHERE ${TriggerHistory.expired}`, { bind: { cutoff }, transaction, type: sequelize_1.QueryTypes.BULKDELETE });
1302
+ }
1303
+ async visibleTriggers(cronId, ids) {
1304
+ return this.database.query(`SELECT ${historyColumns} FROM CronTriggers WHERE cron_id=:cronId AND id IN (:ids)`, { replacements: { cronId, ids }, type: sequelize_1.QueryTypes.SELECT });
1305
+ }
1306
+ async recent(cronId, offset, limit = 25, before) {
1307
+ return this.database.query(`SELECT ${historyColumns}
1308
+ FROM CronTriggers WHERE cron_id=$cronId
1309
+ ${before ? 'AND (observed_at,id) < ($time,$id)' : ''}
1310
+ ORDER BY observed_at DESC,id DESC LIMIT $limit OFFSET $offset`, { bind: Object.assign({ cronId, offset, limit }, before), type: sequelize_1.QueryTypes.SELECT });
1311
+ }
1312
+ async metrics(since) {
1313
+ const [row] = await this.database.query(`WITH today AS (SELECT * FROM CronTriggers WHERE observed_at >= $since),
1314
+ triggers AS (SELECT ABS(observed_at - scheduled_at) AS deviation FROM today WHERE scheduled_at IS NOT NULL),
1315
+ scripts AS (SELECT script_started_at - scheduled_at AS delay FROM today
1316
+ WHERE scheduled_at IS NOT NULL AND script_started_at >= scheduled_at),
1317
+ waits AS (SELECT COALESCE(dequeued_at,started_at) - queued_at AS delay FROM today WHERE COALESCE(dequeued_at,started_at) >= queued_at)
1318
+ SELECT COUNT(*) AS observed, COUNT(CASE WHEN state='skipped' THEN 1 END) AS skipped,
1319
+ COUNT(scheduled_at) AS planned, COUNT(CASE WHEN started_at <= scheduled_at + 5000 THEN 1 END) AS onTime,
1320
+ (SELECT COUNT(*) FROM triggers WHERE deviation <= 5000) AS triggerOnTime,
1321
+ (SELECT deviation FROM triggers ORDER BY deviation LIMIT 1 OFFSET (SELECT MAX(0,(95*COUNT(*)+99)/100-1) FROM triggers)) AS triggerDeviationP95,
1322
+ (SELECT COUNT(*) FROM scripts) AS scriptSamples,
1323
+ (SELECT COUNT(*) FROM scripts WHERE delay <= 5000) AS scriptOnTime,
1324
+ (SELECT delay FROM scripts ORDER BY delay LIMIT 1 OFFSET (SELECT MAX(0,(95*COUNT(*)+99)/100-1) FROM scripts)) AS scriptStartP95,
1325
+ (SELECT COUNT(*) FROM waits) AS samples,
1326
+ (SELECT delay FROM waits ORDER BY delay LIMIT 1 OFFSET (SELECT MAX(0, (95*COUNT(*)+99)/100-1) FROM waits)) AS waitP95
1327
+ FROM today`, { bind: { since }, type: sequelize_1.QueryTypes.SELECT });
1328
+ return Object.assign(Object.assign({}, row), { audit: await (0, scheduleAudit_1.auditSchedule)(this.database, since), systemAudit: await (0, systemScheduleAudit_1.systemScheduleAudit)(this.database, since) });
1329
+ }
1330
+ }
1331
+ exports.TriggerHistory = TriggerHistory;
1332
+ TriggerHistory.expired = `state NOT IN ('queued','running') AND exit_pending IS NOT 1 AND finished_at IS NOT NULL AND observed_at < $cutoff AND finished_at < $cutoff
1333
+ AND NOT EXISTS (SELECT 1 FROM RunningInstances i WHERE i.id=CronTriggers.instance_id AND i.status=0)`;
1334
+ function triggerHistory() {
1335
+ return new TriggerHistory(require('../data').sequelize);
1336
+ }
1337
+ exports.triggerHistory = triggerHistory;
1338
+ //# sourceMappingURL=triggerHistory.js.map