wurk 1.14.0 → 1.15.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 (248) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -2
  3. data/app/controllers/concerns/wurk/same_origin_guard.rb +30 -8
  4. data/app/controllers/wurk/api/pagination.rb +70 -53
  5. data/app/controllers/wurk/api_controller.rb +96 -27
  6. data/app/controllers/wurk/dashboard_controller.rb +26 -2
  7. data/app/controllers/wurk/profiles_controller.rb +28 -23
  8. data/config/routes.rb +8 -6
  9. data/lib/wurk/api/admin.rb +84 -0
  10. data/lib/wurk/api/app.rb +7 -2
  11. data/lib/wurk/api/jobs.rb +11 -3
  12. data/lib/wurk/api/queues.rb +10 -0
  13. data/lib/wurk/api/router.rb +6 -0
  14. data/lib/wurk/api/validation.rb +17 -0
  15. data/lib/wurk/batch/callbacks.rb +9 -2
  16. data/lib/wurk/batch.rb +15 -4
  17. data/lib/wurk/batch_set.rb +22 -0
  18. data/lib/wurk/cli.rb +4 -2
  19. data/lib/wurk/client/buffered.rb +104 -48
  20. data/lib/wurk/configuration.rb +28 -0
  21. data/lib/wurk/fetcher/many_queues.rb +18 -8
  22. data/lib/wurk/fetcher/poison_pill.rb +2 -0
  23. data/lib/wurk/fetcher/reaper.rb +3 -0
  24. data/lib/wurk/fetcher/reliable.rb +26 -12
  25. data/lib/wurk/health.rb +6 -1
  26. data/lib/wurk/health_probe.rb +45 -7
  27. data/lib/wurk/heartbeat.rb +29 -6
  28. data/lib/wurk/job_set.rb +25 -3
  29. data/lib/wurk/leader.rb +2 -0
  30. data/lib/wurk/metrics/accumulator.rb +27 -2
  31. data/lib/wurk/metrics/exposition.rb +45 -0
  32. data/lib/wurk/metrics/history.rb +10 -5
  33. data/lib/wurk/metrics/pool_registry.rb +27 -0
  34. data/lib/wurk/metrics/process_counters.rb +16 -0
  35. data/lib/wurk/metrics/process_families.rb +115 -0
  36. data/lib/wurk/metrics/prometheus.rb +84 -51
  37. data/lib/wurk/redis_pool.rb +6 -1
  38. data/lib/wurk/scheduled.rb +7 -0
  39. data/lib/wurk/swarm/child_boot.rb +6 -1
  40. data/lib/wurk/swarm/crash_watch.rb +5 -0
  41. data/lib/wurk/swarm/memory_watch.rb +1 -7
  42. data/lib/wurk/swarm/restart.rb +14 -5
  43. data/lib/wurk/swarm/restart_counters.rb +79 -0
  44. data/lib/wurk/swarm.rb +14 -6
  45. data/lib/wurk/version.rb +1 -1
  46. data/lib/wurk.rb +2 -1
  47. data/vendor/assets/dashboard/assets/{ArgsValue-BSTICTw4.js → ArgsValue-DSNRXbbF.js} +1 -1
  48. data/vendor/assets/dashboard/assets/ArgsValue-DSNRXbbF.js.br +0 -0
  49. data/vendor/assets/dashboard/assets/ArgsValue-DSNRXbbF.js.gz +0 -0
  50. data/vendor/assets/dashboard/assets/{BatchDetail-BBMiNTok.js → BatchDetail-DbddHvay.js} +1 -1
  51. data/vendor/assets/dashboard/assets/BatchDetail-DbddHvay.js.br +0 -0
  52. data/vendor/assets/dashboard/assets/BatchDetail-DbddHvay.js.gz +0 -0
  53. data/vendor/assets/dashboard/assets/Batches-D-qS6l6A.js +1 -0
  54. data/vendor/assets/dashboard/assets/Batches-D-qS6l6A.js.br +0 -0
  55. data/vendor/assets/dashboard/assets/Batches-D-qS6l6A.js.gz +0 -0
  56. data/vendor/assets/dashboard/assets/{Busy-CcSvIQFY.js → Busy-BYEpKo6H.js} +1 -1
  57. data/vendor/assets/dashboard/assets/Busy-BYEpKo6H.js.br +0 -0
  58. data/vendor/assets/dashboard/assets/Busy-BYEpKo6H.js.gz +0 -0
  59. data/vendor/assets/dashboard/assets/{Cron-ByRxtItH.js → Cron-BOTMv9J0.js} +1 -1
  60. data/vendor/assets/dashboard/assets/Cron-BOTMv9J0.js.br +0 -0
  61. data/vendor/assets/dashboard/assets/Cron-BOTMv9J0.js.gz +0 -0
  62. data/vendor/assets/dashboard/assets/Dashboard-BmdMHA0S.js +1 -0
  63. data/vendor/assets/dashboard/assets/Dashboard-BmdMHA0S.js.br +0 -0
  64. data/vendor/assets/dashboard/assets/Dashboard-BmdMHA0S.js.gz +0 -0
  65. data/vendor/assets/dashboard/assets/Dead-CmoKRD2C.js +1 -0
  66. data/vendor/assets/dashboard/assets/Dead-CmoKRD2C.js.br +0 -0
  67. data/vendor/assets/dashboard/assets/Dead-CmoKRD2C.js.gz +0 -0
  68. data/vendor/assets/dashboard/assets/{Extension--fRIfdcW.js → Extension-BhP5isgr.js} +1 -1
  69. data/vendor/assets/dashboard/assets/Extension-BhP5isgr.js.br +0 -0
  70. data/vendor/assets/dashboard/assets/Extension-BhP5isgr.js.gz +0 -0
  71. data/vendor/assets/dashboard/assets/FilterBox-DBIZXNtY.js +1 -0
  72. data/vendor/assets/dashboard/assets/FilterBox-DBIZXNtY.js.br +0 -0
  73. data/vendor/assets/dashboard/assets/FilterBox-DBIZXNtY.js.gz +0 -0
  74. data/vendor/assets/dashboard/assets/{FlowDetail-CxmWxNpF.js → FlowDetail-CN97QgjE.js} +1 -1
  75. data/vendor/assets/dashboard/assets/FlowDetail-CN97QgjE.js.br +0 -0
  76. data/vendor/assets/dashboard/assets/FlowDetail-CN97QgjE.js.gz +0 -0
  77. data/vendor/assets/dashboard/assets/{FlowState-ClzInw0-.js → FlowState-B04ZLDe-.js} +1 -1
  78. data/vendor/assets/dashboard/assets/FlowState-B04ZLDe-.js.br +0 -0
  79. data/vendor/assets/dashboard/assets/FlowState-B04ZLDe-.js.gz +0 -0
  80. data/vendor/assets/dashboard/assets/{Flows-CCnTVfkN.js → Flows-CJaBWl24.js} +1 -1
  81. data/vendor/assets/dashboard/assets/Flows-CJaBWl24.js.br +0 -0
  82. data/vendor/assets/dashboard/assets/Flows-CJaBWl24.js.gz +0 -0
  83. data/vendor/assets/dashboard/assets/{JobDetailModal-Btzt9HOQ.js → JobDetailModal-BKxX4Wpk.js} +1 -1
  84. data/vendor/assets/dashboard/assets/JobDetailModal-BKxX4Wpk.js.br +0 -0
  85. data/vendor/assets/dashboard/assets/JobDetailModal-BKxX4Wpk.js.gz +0 -0
  86. data/vendor/assets/dashboard/assets/{Limiters-DYxSN0sy.js → Limiters-RqxwfODD.js} +1 -1
  87. data/vendor/assets/dashboard/assets/Limiters-RqxwfODD.js.br +0 -0
  88. data/vendor/assets/dashboard/assets/Limiters-RqxwfODD.js.gz +0 -0
  89. data/vendor/assets/dashboard/assets/{Metrics-BfSRkQ2U.js → Metrics-Qyfu0K6J.js} +1 -1
  90. data/vendor/assets/dashboard/assets/Metrics-Qyfu0K6J.js.br +0 -0
  91. data/vendor/assets/dashboard/assets/Metrics-Qyfu0K6J.js.gz +0 -0
  92. data/vendor/assets/dashboard/assets/{NotFound-DrAE8U92.js → NotFound-CQozbLGO.js} +1 -1
  93. data/vendor/assets/dashboard/assets/NotFound-CQozbLGO.js.br +0 -0
  94. data/vendor/assets/dashboard/assets/NotFound-CQozbLGO.js.gz +0 -0
  95. data/vendor/assets/dashboard/assets/{PageHeader-w3hA_hMm.js → PageHeader-BDXaICrU.js} +1 -1
  96. data/vendor/assets/dashboard/assets/PageHeader-BDXaICrU.js.br +0 -0
  97. data/vendor/assets/dashboard/assets/PageHeader-BDXaICrU.js.gz +0 -0
  98. data/vendor/assets/dashboard/assets/Profiles-DpMDGxoE.js +1 -0
  99. data/vendor/assets/dashboard/assets/Profiles-DpMDGxoE.js.br +0 -0
  100. data/vendor/assets/dashboard/assets/Profiles-DpMDGxoE.js.gz +0 -0
  101. data/vendor/assets/dashboard/assets/Queues-B2RVkHLs.js +1 -0
  102. data/vendor/assets/dashboard/assets/Queues-B2RVkHLs.js.br +0 -0
  103. data/vendor/assets/dashboard/assets/Queues-B2RVkHLs.js.gz +0 -0
  104. data/vendor/assets/dashboard/assets/Retries-C2sAd4Gk.js +1 -0
  105. data/vendor/assets/dashboard/assets/Retries-C2sAd4Gk.js.br +0 -0
  106. data/vendor/assets/dashboard/assets/Retries-C2sAd4Gk.js.gz +0 -0
  107. data/vendor/assets/dashboard/assets/Scheduled-CKPcR-0t.js +1 -0
  108. data/vendor/assets/dashboard/assets/Scheduled-CKPcR-0t.js.br +0 -0
  109. data/vendor/assets/dashboard/assets/Scheduled-CKPcR-0t.js.gz +0 -0
  110. data/vendor/assets/dashboard/assets/{Search-D42Va7lB.js → Search-KvJ7HjUn.js} +1 -1
  111. data/vendor/assets/dashboard/assets/Search-KvJ7HjUn.js.br +0 -0
  112. data/vendor/assets/dashboard/assets/Search-KvJ7HjUn.js.gz +0 -0
  113. data/vendor/assets/dashboard/assets/ar-CugpXGea.js +1 -0
  114. data/vendor/assets/dashboard/assets/ar-CugpXGea.js.br +0 -0
  115. data/vendor/assets/dashboard/assets/ar-CugpXGea.js.gz +0 -0
  116. data/vendor/assets/dashboard/assets/{charts-C1xMUYFp.js → charts-CSwj2Y-E.js} +1 -1
  117. data/vendor/assets/dashboard/assets/charts-CSwj2Y-E.js.br +0 -0
  118. data/vendor/assets/dashboard/assets/charts-CSwj2Y-E.js.gz +0 -0
  119. data/vendor/assets/dashboard/assets/de-Bl5Jn_0l.js +1 -0
  120. data/vendor/assets/dashboard/assets/de-Bl5Jn_0l.js.br +0 -0
  121. data/vendor/assets/dashboard/assets/de-Bl5Jn_0l.js.gz +0 -0
  122. data/vendor/assets/dashboard/assets/es-lqQrmjYI.js +1 -0
  123. data/vendor/assets/dashboard/assets/es-lqQrmjYI.js.br +0 -0
  124. data/vendor/assets/dashboard/assets/es-lqQrmjYI.js.gz +0 -0
  125. data/vendor/assets/dashboard/assets/fr-D70VBoh3.js +1 -0
  126. data/vendor/assets/dashboard/assets/fr-D70VBoh3.js.br +0 -0
  127. data/vendor/assets/dashboard/assets/fr-D70VBoh3.js.gz +0 -0
  128. data/vendor/assets/dashboard/assets/{i18n-BXp3XejR.js → i18n-DdPClaCG.js} +1 -1
  129. data/vendor/assets/dashboard/assets/i18n-DdPClaCG.js.br +0 -0
  130. data/vendor/assets/dashboard/assets/i18n-DdPClaCG.js.gz +0 -0
  131. data/vendor/assets/dashboard/assets/{index-CiLU1zz8.js → index-DdMJr-ZQ.js} +3 -3
  132. data/vendor/assets/dashboard/assets/index-DdMJr-ZQ.js.br +0 -0
  133. data/vendor/assets/dashboard/assets/index-DdMJr-ZQ.js.gz +0 -0
  134. data/vendor/assets/dashboard/assets/index-U83KcqT1.css +1 -0
  135. data/vendor/assets/dashboard/assets/index-U83KcqT1.css.br +0 -0
  136. data/vendor/assets/dashboard/assets/index-U83KcqT1.css.gz +0 -0
  137. data/vendor/assets/dashboard/assets/ja-BYMqnHjg.js +1 -0
  138. data/vendor/assets/dashboard/assets/ja-BYMqnHjg.js.br +0 -0
  139. data/vendor/assets/dashboard/assets/ja-BYMqnHjg.js.gz +0 -0
  140. data/vendor/assets/dashboard/assets/pt-BR-4k5M2MYH.js +1 -0
  141. data/vendor/assets/dashboard/assets/pt-BR-4k5M2MYH.js.br +0 -0
  142. data/vendor/assets/dashboard/assets/pt-BR-4k5M2MYH.js.gz +0 -0
  143. data/vendor/assets/dashboard/assets/useJobSetList-BDkKIAvU.js +2 -0
  144. data/vendor/assets/dashboard/assets/useJobSetList-BDkKIAvU.js.br +0 -0
  145. data/vendor/assets/dashboard/assets/useJobSetList-BDkKIAvU.js.gz +0 -0
  146. data/vendor/assets/dashboard/assets/{useResetPageOnEmpty-Cuv4BHkC.js → useResetPageOnEmpty-DHrPaV9z.js} +1 -1
  147. data/vendor/assets/dashboard/assets/useResetPageOnEmpty-DHrPaV9z.js.br +0 -0
  148. data/vendor/assets/dashboard/assets/useResetPageOnEmpty-DHrPaV9z.js.gz +0 -0
  149. data/vendor/assets/dashboard/assets/{useSort-V9yUrByY.js → useSort-5-b2NAdA.js} +1 -1
  150. data/vendor/assets/dashboard/assets/useSort-5-b2NAdA.js.br +0 -0
  151. data/vendor/assets/dashboard/assets/useSort-5-b2NAdA.js.gz +0 -0
  152. data/vendor/assets/dashboard/assets/{utils-69XSoGbQ.js → utils-Az0d2-xz.js} +1 -1
  153. data/vendor/assets/dashboard/assets/utils-Az0d2-xz.js.br +0 -0
  154. data/vendor/assets/dashboard/assets/utils-Az0d2-xz.js.gz +0 -0
  155. data/vendor/assets/dashboard/assets/zh-CN-B9E1MvsM.js +1 -0
  156. data/vendor/assets/dashboard/assets/zh-CN-B9E1MvsM.js.br +0 -0
  157. data/vendor/assets/dashboard/assets/zh-CN-B9E1MvsM.js.gz +0 -0
  158. data/vendor/assets/dashboard/index.html +8 -8
  159. data/vendor/assets/dashboard/wurk-manifest.json +2 -2
  160. metadata +117 -109
  161. data/vendor/assets/dashboard/assets/ArgsValue-BSTICTw4.js.br +0 -0
  162. data/vendor/assets/dashboard/assets/ArgsValue-BSTICTw4.js.gz +0 -0
  163. data/vendor/assets/dashboard/assets/BatchDetail-BBMiNTok.js.br +0 -0
  164. data/vendor/assets/dashboard/assets/BatchDetail-BBMiNTok.js.gz +0 -0
  165. data/vendor/assets/dashboard/assets/Batches-D8I3hCXy.js +0 -1
  166. data/vendor/assets/dashboard/assets/Batches-D8I3hCXy.js.br +0 -0
  167. data/vendor/assets/dashboard/assets/Batches-D8I3hCXy.js.gz +0 -0
  168. data/vendor/assets/dashboard/assets/Busy-CcSvIQFY.js.br +0 -0
  169. data/vendor/assets/dashboard/assets/Busy-CcSvIQFY.js.gz +0 -0
  170. data/vendor/assets/dashboard/assets/Cron-ByRxtItH.js.br +0 -0
  171. data/vendor/assets/dashboard/assets/Cron-ByRxtItH.js.gz +0 -0
  172. data/vendor/assets/dashboard/assets/Dashboard-CO7_6OUM.js +0 -1
  173. data/vendor/assets/dashboard/assets/Dashboard-CO7_6OUM.js.br +0 -0
  174. data/vendor/assets/dashboard/assets/Dashboard-CO7_6OUM.js.gz +0 -0
  175. data/vendor/assets/dashboard/assets/Dead-C8mDGQAF.js +0 -1
  176. data/vendor/assets/dashboard/assets/Dead-C8mDGQAF.js.br +0 -0
  177. data/vendor/assets/dashboard/assets/Dead-C8mDGQAF.js.gz +0 -0
  178. data/vendor/assets/dashboard/assets/Extension--fRIfdcW.js.br +0 -0
  179. data/vendor/assets/dashboard/assets/Extension--fRIfdcW.js.gz +0 -0
  180. data/vendor/assets/dashboard/assets/FilterBox-BS1_G5S5.js +0 -2
  181. data/vendor/assets/dashboard/assets/FilterBox-BS1_G5S5.js.br +0 -0
  182. data/vendor/assets/dashboard/assets/FilterBox-BS1_G5S5.js.gz +0 -0
  183. data/vendor/assets/dashboard/assets/FlowDetail-CxmWxNpF.js.br +0 -0
  184. data/vendor/assets/dashboard/assets/FlowDetail-CxmWxNpF.js.gz +0 -0
  185. data/vendor/assets/dashboard/assets/FlowState-ClzInw0-.js.br +0 -0
  186. data/vendor/assets/dashboard/assets/FlowState-ClzInw0-.js.gz +0 -0
  187. data/vendor/assets/dashboard/assets/Flows-CCnTVfkN.js.br +0 -0
  188. data/vendor/assets/dashboard/assets/Flows-CCnTVfkN.js.gz +0 -0
  189. data/vendor/assets/dashboard/assets/JobDetailModal-Btzt9HOQ.js.br +0 -0
  190. data/vendor/assets/dashboard/assets/JobDetailModal-Btzt9HOQ.js.gz +0 -0
  191. data/vendor/assets/dashboard/assets/Limiters-DYxSN0sy.js.br +0 -0
  192. data/vendor/assets/dashboard/assets/Limiters-DYxSN0sy.js.gz +0 -0
  193. data/vendor/assets/dashboard/assets/Metrics-BfSRkQ2U.js.br +0 -0
  194. data/vendor/assets/dashboard/assets/Metrics-BfSRkQ2U.js.gz +0 -0
  195. data/vendor/assets/dashboard/assets/NotFound-DrAE8U92.js.br +0 -0
  196. data/vendor/assets/dashboard/assets/NotFound-DrAE8U92.js.gz +0 -0
  197. data/vendor/assets/dashboard/assets/PageHeader-w3hA_hMm.js.br +0 -0
  198. data/vendor/assets/dashboard/assets/PageHeader-w3hA_hMm.js.gz +0 -0
  199. data/vendor/assets/dashboard/assets/Profiles-191Gq7P-.js +0 -1
  200. data/vendor/assets/dashboard/assets/Profiles-191Gq7P-.js.br +0 -0
  201. data/vendor/assets/dashboard/assets/Profiles-191Gq7P-.js.gz +0 -0
  202. data/vendor/assets/dashboard/assets/Queues-CIvl1fjf.js +0 -1
  203. data/vendor/assets/dashboard/assets/Queues-CIvl1fjf.js.br +0 -0
  204. data/vendor/assets/dashboard/assets/Queues-CIvl1fjf.js.gz +0 -0
  205. data/vendor/assets/dashboard/assets/Retries-sdaiHACO.js +0 -1
  206. data/vendor/assets/dashboard/assets/Retries-sdaiHACO.js.br +0 -0
  207. data/vendor/assets/dashboard/assets/Retries-sdaiHACO.js.gz +0 -0
  208. data/vendor/assets/dashboard/assets/Scheduled-CcildKBh.js +0 -1
  209. data/vendor/assets/dashboard/assets/Scheduled-CcildKBh.js.br +0 -0
  210. data/vendor/assets/dashboard/assets/Scheduled-CcildKBh.js.gz +0 -0
  211. data/vendor/assets/dashboard/assets/Search-D42Va7lB.js.br +0 -0
  212. data/vendor/assets/dashboard/assets/Search-D42Va7lB.js.gz +0 -0
  213. data/vendor/assets/dashboard/assets/ar-Br6DtdyK.js +0 -1
  214. data/vendor/assets/dashboard/assets/ar-Br6DtdyK.js.br +0 -0
  215. data/vendor/assets/dashboard/assets/ar-Br6DtdyK.js.gz +0 -0
  216. data/vendor/assets/dashboard/assets/charts-C1xMUYFp.js.br +0 -0
  217. data/vendor/assets/dashboard/assets/charts-C1xMUYFp.js.gz +0 -0
  218. data/vendor/assets/dashboard/assets/de-B2NCIuzo.js +0 -1
  219. data/vendor/assets/dashboard/assets/de-B2NCIuzo.js.br +0 -0
  220. data/vendor/assets/dashboard/assets/de-B2NCIuzo.js.gz +0 -0
  221. data/vendor/assets/dashboard/assets/es-BGeu_JNB.js +0 -1
  222. data/vendor/assets/dashboard/assets/es-BGeu_JNB.js.br +0 -0
  223. data/vendor/assets/dashboard/assets/es-BGeu_JNB.js.gz +0 -0
  224. data/vendor/assets/dashboard/assets/fr-DQVBWFId.js +0 -1
  225. data/vendor/assets/dashboard/assets/fr-DQVBWFId.js.br +0 -0
  226. data/vendor/assets/dashboard/assets/fr-DQVBWFId.js.gz +0 -0
  227. data/vendor/assets/dashboard/assets/i18n-BXp3XejR.js.br +0 -0
  228. data/vendor/assets/dashboard/assets/i18n-BXp3XejR.js.gz +0 -0
  229. data/vendor/assets/dashboard/assets/index-CiLU1zz8.js.br +0 -0
  230. data/vendor/assets/dashboard/assets/index-CiLU1zz8.js.gz +0 -0
  231. data/vendor/assets/dashboard/assets/index-r3T9Ugl4.css +0 -1
  232. data/vendor/assets/dashboard/assets/index-r3T9Ugl4.css.br +0 -0
  233. data/vendor/assets/dashboard/assets/index-r3T9Ugl4.css.gz +0 -0
  234. data/vendor/assets/dashboard/assets/ja-D06IBqzL.js +0 -1
  235. data/vendor/assets/dashboard/assets/ja-D06IBqzL.js.br +0 -0
  236. data/vendor/assets/dashboard/assets/ja-D06IBqzL.js.gz +0 -0
  237. data/vendor/assets/dashboard/assets/pt-BR-Dn_okdxf.js +0 -1
  238. data/vendor/assets/dashboard/assets/pt-BR-Dn_okdxf.js.br +0 -0
  239. data/vendor/assets/dashboard/assets/pt-BR-Dn_okdxf.js.gz +0 -0
  240. data/vendor/assets/dashboard/assets/useResetPageOnEmpty-Cuv4BHkC.js.br +0 -0
  241. data/vendor/assets/dashboard/assets/useResetPageOnEmpty-Cuv4BHkC.js.gz +0 -0
  242. data/vendor/assets/dashboard/assets/useSort-V9yUrByY.js.br +0 -0
  243. data/vendor/assets/dashboard/assets/useSort-V9yUrByY.js.gz +0 -0
  244. data/vendor/assets/dashboard/assets/utils-69XSoGbQ.js.br +0 -0
  245. data/vendor/assets/dashboard/assets/utils-69XSoGbQ.js.gz +0 -0
  246. data/vendor/assets/dashboard/assets/zh-CN-B1ObO-uZ.js +0 -1
  247. data/vendor/assets/dashboard/assets/zh-CN-B1ObO-uZ.js.br +0 -0
  248. data/vendor/assets/dashboard/assets/zh-CN-B1ObO-uZ.js.gz +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d7d139e1779564e4d49dcc71ddc85c4ce8e25e20b3420743fc29298a484b18f0
4
- data.tar.gz: df27c0bb967bbe3e2a4098c5d50c3e7b20b5bc5c475f38e01b23dab82e4aa2a4
3
+ metadata.gz: 108f3423d4ca0de8cd1a87d25387c9a98bac9003ded84644660d2802dd0264cd
4
+ data.tar.gz: f29ef41d0119297c1f63ad1b9e7e81e35912a0cbeed3cf6ba4691a98061176ec
5
5
  SHA512:
6
- metadata.gz: d03b162bcdeddaf1405432950e1793343dfeccec299c9ad8acf99e80da2f6f984cb736916d29b97f68eb0de45cd587c1bbf862bd5778b840b73cba01064b34fe
7
- data.tar.gz: 7717cd43bb4c01567daaef09d471b8793edb7c5e0be7460428d6be15208dbffe880acb929ad52b180dafe118a0df42dc5009965d47cbb47d4d372a94f860909f
6
+ metadata.gz: dd822aa1cd83936d5f62c36976e4d25408833d65d5e46380de3e02312cd5a339dd56e0695876d41c380bac90939312f32d19ca10e4477d34e89f32c931411553
7
+ data.tar.gz: 5168f25c22adf0d41206ebba58f0bc599391377639caad225219615c908c5a5bef4822f5713c51be7c6e321277149b5ee94b23ab7c830f1cca3f712b79f9d5a3
data/README.md CHANGED
@@ -303,9 +303,9 @@ Wurk is MIT and stays that way. If what you need is a commercial support contrac
303
303
  + gem "wurk"
304
304
  ```
305
305
 
306
- `bundle install && restart`. The worker command stays as it was: Wurk ships `sidekiq` and `sidekiqswarm` executables, so `bundle exec sidekiq -C config/sidekiq.yml` in a Procfile or manifest keeps working. Wurk reads and writes the same Redis schema, so there is no data migration: Wurk picks up the queues, schedules, retries, batches and periodic loops Sidekiq left behind. Running Sidekiq and Wurk workers against one Redis *at the same time* is not tested yet, so a live production move is a **drain cutover** (stop Sidekiq's workers, confirm nothing is in flight, start Wurk), with a matching rollback; the [production cutover](https://github.com/developerz-ai/wurk/blob/main/docs/migrate-from-sidekiq.md#9-production-cutover) section has every step and command. The upstream suites of sidekiq-cron, sidekiq-unique-jobs, sidekiq-failures and sentry-sidekiq run against Wurk in the [`ecosystem` CI job](https://github.com/developerz-ai/wurk/blob/main/.github/workflows/ecosystem.yml) (see [`test/ecosystem/`](https://github.com/developerz-ai/wurk/tree/main/test/ecosystem)). sidekiq-scheduler, sidekiq-status and sidekiq-throttled are target additions tracked in [docs/idea/14-ecosystem-compat.md](https://github.com/developerz-ai/wurk/blob/main/docs/idea/14-ecosystem-compat.md).
306
+ `bundle install && restart`. The worker command stays as it was: Wurk ships `sidekiq` and `sidekiqswarm` executables, so `bundle exec sidekiq -C config/sidekiq.yml` in a Procfile or manifest keeps working. Wurk reads and writes the same Redis schema, so there is no data migration: Wurk picks up the queues, schedules, retries, batches and periodic loops Sidekiq left behind. Running Sidekiq and Wurk workers against one Redis *at the same time* is tested for stock Sidekiq 8 only, which may roll from one to the other under the conditions the guide lists; for a Sidekiq 7.x, Pro or Enterprise app a live production move is a **drain cutover** (stop Sidekiq's workers, confirm nothing is in flight, start Wurk), with a matching rollback. The [production cutover](https://github.com/developerz-ai/wurk/blob/main/docs/migrate-from-sidekiq.md#9-production-cutover) section has every step and command. The upstream suites of sidekiq-cron, sidekiq-unique-jobs, sidekiq-failures and sentry-sidekiq run against Wurk in the [`ecosystem` CI job](https://github.com/developerz-ai/wurk/blob/main/.github/workflows/ecosystem.yml) (see [`test/ecosystem/`](https://github.com/developerz-ai/wurk/tree/main/test/ecosystem)). sidekiq-scheduler, sidekiq-status and sidekiq-throttled are target additions tracked in [docs/idea/14-ecosystem-compat.md](https://github.com/developerz-ai/wurk/blob/main/docs/idea/14-ecosystem-compat.md).
307
307
 
308
- **Keeping a `sidekiq-*` add-on gem?** Those gems declare `add_dependency "sidekiq"`, which would reinstall real Sidekiq next to Wurk. Satisfy it with Wurk's git-only [`sidekiq` shim gem](https://github.com/developerz-ai/wurk/tree/main/ecosystem/sidekiq-shim) instead, pinned to the tag of the Wurk release you run: `gem "sidekiq", github: "developerz-ai/wurk", tag: "v1.14.0", glob: "ecosystem/sidekiq-shim/*.gemspec"`. Only sidekiq-cron, sidekiq-unique-jobs, sidekiq-failures and sentry-sidekiq are exercised that way, by the `ecosystem` workflow; treat the others as untested.
308
+ **Keeping a `sidekiq-*` add-on gem?** Those gems declare `add_dependency "sidekiq"`, which would reinstall real Sidekiq next to Wurk. Satisfy it with Wurk's git-only [`sidekiq` shim gem](https://github.com/developerz-ai/wurk/tree/main/ecosystem/sidekiq-shim) instead, pinned to the tag of the Wurk release you run: `gem "sidekiq", github: "developerz-ai/wurk", tag: "v1.15.1", glob: "ecosystem/sidekiq-shim/*.gemspec"`. Only sidekiq-cron, sidekiq-unique-jobs, sidekiq-failures and sentry-sidekiq are exercised that way, by the `ecosystem` workflow; treat the others as untested.
309
309
 
310
310
  Full walkthrough — config side-by-side, the Redis key/`sidekiq_options` mapping, known incompatibilities, moving sidekiq-cron schedules over (`rake wurk:import:cron`), and the production cutover and rollback playbook: **[docs/migrate-from-sidekiq.md](https://github.com/developerz-ai/wurk/blob/main/docs/migrate-from-sidekiq.md)**. On the night, keep the **[incident runbook](https://github.com/developerz-ai/wurk/blob/main/docs/runbook.md)** open.
311
311
 
@@ -6,12 +6,18 @@ module Wurk
6
6
  # extension forms send no Rails authenticity token, so `protect_from_forgery`
7
7
  # can't apply — guard unsafe methods with a same-origin check instead. A
8
8
  # cross-site page can drive a victim's browser but cannot forge
9
- # `Sec-Fetch-Site: same-origin` (the browser sets it); a missing header is
10
- # denied too, since only a non-browser client omits it and it carries no
11
- # ambient session cookie to abuse.
9
+ # `Sec-Fetch-Site: same-origin` (the browser sets it).
12
10
  #
13
- # Mirrors the standalone Rack surface (Wurk::Web#safe_request?) so every
14
- # mutating dashboard entry point enforces one rule.
11
+ # Browsers send Fetch Metadata only to potentially-trustworthy origins
12
+ # (HTTPS, localhost), so a dashboard over plain HTTP on a LAN host never sees
13
+ # it. Then the request's `Origin` — or, when absent, its `Referer` — must be
14
+ # exactly this request's scheme, host and port (owner decision U9, #101 W3).
15
+ # Neither header present is denied: only a non-browser client omits both,
16
+ # and it carries no ambient session cookie to abuse.
17
+ #
18
+ # The standalone Rack surface (Wurk::Web#safe_request?) applies the same
19
+ # Sec-Fetch-Site rule without this fallback: it stays strict, so a
20
+ # plain-HTTP standalone mount refuses unsafe requests (parity-divergences).
15
21
  module SameOriginGuard
16
22
  extend ActiveSupport::Concern
17
23
 
@@ -28,13 +34,29 @@ module Wurk
28
34
 
29
35
  private
30
36
 
37
+ # The SPA's toast branches on this body to name the cause instead of
38
+ # reading the 403 as read-only mode.
31
39
  def verify_same_origin!
32
- head :forbidden unless safe_request?
40
+ render json: { error: 'cross_origin' }, status: :forbidden unless safe_request?
33
41
  end
34
42
 
35
43
  def safe_request?
36
- SAFE_METHODS.include?(request.request_method) ||
37
- request.headers['Sec-Fetch-Site'] == 'same-origin'
44
+ return true if SAFE_METHODS.include?(request.request_method)
45
+
46
+ site = request.headers['Sec-Fetch-Site']
47
+ site ? site == 'same-origin' : same_origin_source?
48
+ end
49
+
50
+ def same_origin_source?
51
+ source = request.headers['Origin'].presence || request.referer.presence
52
+ return false unless source
53
+
54
+ uri = ::URI.parse(source)
55
+ [uri.scheme, uri.host, uri.port] == own_origin
56
+ rescue ::URI::InvalidURIError
57
+ false
38
58
  end
59
+
60
+ def own_origin = [request.scheme, request.host, request.port]
39
61
  end
40
62
  end
@@ -5,7 +5,8 @@ module Wurk
5
5
  # Pagination helpers shared by every listing endpoint. The contract:
6
6
  # * `?count=` page size (default 25, clamped to 1..200)
7
7
  # * `?page=` 0-indexed page number
8
- # * `?substr=` case-insensitive klass/jid filter on the page
8
+ # * `?substr=` case-insensitive filter on a row's klass, jid, error
9
+ # class, error message or args
9
10
  #
10
11
  # Helpers expect an Enumerable that yields whatever JSON-shaped Hash the
11
12
  # caller built; substr filtering and slicing happen after serialization so
@@ -14,15 +15,25 @@ module Wurk
14
15
  DEFAULT_PAGE_SIZE = 25
15
16
  MAX_PAGE_SIZE = 200
16
17
  # An unfiltered listing reads its page at the offset (the set's
17
- # #snapshot), whatever the depth; the walks that remain (#slice on a set
18
- # without one, the Limits names) still pay per skipped row, and 1000
19
- # pages is far beyond any real UI depth while bounding them.
18
+ # #snapshot), whatever the depth; the walks that remain (a filtered
19
+ # #slice, the Limits names) still pay per skipped row, and 1000 pages is
20
+ # far beyond any real UI depth while bounding them.
20
21
  MAX_PAGE = 1_000
21
22
  # A substr that matches nothing would otherwise stream the whole backing
22
- # set through Ruby (same DoS shape Web::Search bounds with SCAN_BUDGET).
23
- # Raw rows examined per filtered request; results within the budget are
24
- # exact, beyond it the page just comes back short.
25
- FILTER_SCAN_LIMIT = 20_000
23
+ # set through Ruby, so a filtered request examines at most Web::Search's
24
+ # per-request budget of raw rows; results within it are exact, beyond it
25
+ # the page just comes back short.
26
+ FILTER_SCAN_LIMIT = ::Wurk::Web::Search::SCAN_BUDGET
27
+ # A filter walk reads the set through its #snapshot, starting at an
28
+ # ordinary listing page and doubling to FILTER_PAGE: a match near the
29
+ # top costs what it did, and the full budget costs ~25 round trips
30
+ # rather than one per 50 rows.
31
+ FIRST_FILTER_PAGE = 50
32
+ FILTER_PAGE = 1_000
33
+ # Entries one filtered `<set>/all/:cmd` request acts on, the cap the
34
+ # bulk `keys[]` action already has.
35
+ SWEEP_LIMIT = 1_000
36
+ MATCHED_FIELDS = %i[klass jid error_class error_message].freeze
26
37
 
27
38
  module_function
28
39
 
@@ -61,49 +72,15 @@ module Wurk
61
72
  default
62
73
  end
63
74
 
64
- # Iterates `enumerable` and collects up to `count` payloads from the
65
- # requested page after substr filtering. `block` maps each member to a
66
- # JSON Hash; nil from the block skips the member entirely.
67
- #
68
- # With a substr filter the offset must count *matching* rows, not raw
69
- # rows — otherwise page N restarts at raw index N*count and re-emits
70
- # (or skips) matches already assigned to earlier pages. Without a
71
- # filter we keep the fast path that skips serialization before the
72
- # offset.
73
- def slice(enumerable, page, &)
74
- if page[:substr].empty?
75
- slice_raw(enumerable, offset(page), page[:count], &)
76
- else
77
- slice_filtered(enumerable, offset(page), page, &)
78
- end
79
- end
80
-
81
- # Fast path: skip serialization entirely for rows before the offset.
82
- def slice_raw(enumerable, offset, count)
83
- results = []
84
- seen = 0
85
- enumerable.each do |member|
86
- if seen < offset
87
- seen += 1
88
- next
89
- end
90
-
91
- payload = yield(member)
92
- next unless payload
93
-
94
- results << payload
95
- break if results.size >= count
96
- end
97
- results
98
- end
99
-
100
- # Filtered path: the offset counts MATCHING rows, so page boundaries
101
- # stay stable (raw-index offsets re-emit or skip matches across pages).
102
- # Records the matches seen in `page[:matched]` and whether the set was
103
- # walked to its end in `page[:exhausted]`: stopping once the page fills
104
- # is what keeps a filtered request cheap, so the count is only exact
105
- # when nothing was left unread.
106
- def slice_filtered(enumerable, offset, page)
75
+ # One page of a filtered listing: up to `count` payloads (the block maps
76
+ # each member to one; nil skips it) from the matches of `substr`, in
77
+ # `enumerable`'s order. The offset counts MATCHING rows, so page
78
+ # boundaries stay stable (raw-index offsets re-emit or skip matches
79
+ # across pages). Records the matches seen in `page[:matched]` and whether
80
+ # the set was walked to its end in `page[:exhausted]`: stopping once the
81
+ # page fills is what keeps a filtered request cheap, so the count is only
82
+ # exact when nothing was left unread.
83
+ def slice(enumerable, page)
107
84
  results = []
108
85
  matched = 0
109
86
  examined = 0
@@ -113,7 +90,7 @@ module Wurk
113
90
  payload = yield(member)
114
91
  next unless payload && match?(payload, page[:substr])
115
92
 
116
- results << payload if (matched += 1) > offset
93
+ results << payload if (matched += 1) > offset(page)
117
94
  break if results.size >= page[:count]
118
95
  end
119
96
  record_match_count(page, matched, examined, results.size)
@@ -125,11 +102,51 @@ module Wurk
125
102
  page[:exhausted] = examined <= FILTER_SCAN_LIMIT && served < page[:count]
126
103
  end
127
104
 
105
+ # Up to SWEEP_LIMIT of `rows`' members whose row (the block maps a member
106
+ # to it) matches `substr`, within FILTER_SCAN_LIMIT examined:
107
+ # [members, rows examined, whether `rows` ran out].
108
+ def matching(rows, substr)
109
+ members = []
110
+ examined = 0
111
+ rows.each do |member|
112
+ return [members, examined, false] if examined >= FILTER_SCAN_LIMIT || members.size >= SWEEP_LIMIT
113
+
114
+ examined += 1
115
+ members << member if match?(yield(member), substr)
116
+ end
117
+ [members, examined, true]
118
+ end
119
+
120
+ # Every row from raw offset `from` on, read page by page through the
121
+ # block, which answers `count` rows from `offset` in listing order.
122
+ # Stops after the first short page.
123
+ def walk(from = 0, &read)
124
+ ::Enumerator.new do |out|
125
+ offset = from
126
+ size = FIRST_FILTER_PAGE
127
+ loop do
128
+ rows = read.call(offset, size)
129
+ rows.each { |row| out << row }
130
+ break if rows.size < size
131
+
132
+ offset += size
133
+ size = [size * 2, FILTER_PAGE].min
134
+ end
135
+ end
136
+ end
137
+
128
138
  def match?(payload, substr)
129
139
  return true if substr.nil? || substr.empty?
130
140
 
131
141
  needle = substr.downcase
132
- payload[:klass].to_s.downcase.include?(needle) || payload[:jid].to_s.downcase.include?(needle)
142
+ MATCHED_FIELDS.any? { |field| payload[field].to_s.downcase.include?(needle) } ||
143
+ args_match?(payload[:args], needle)
144
+ end
145
+
146
+ # Against the args as the SPA shows them: JSON, so `"a@b.c"` or `42]`
147
+ # match as typed.
148
+ def args_match?(args, needle)
149
+ !args.nil? && ::Wurk.dump_json(args).downcase.include?(needle)
133
150
  end
134
151
  end
135
152
  end
@@ -35,6 +35,10 @@ module Wurk
35
35
 
36
36
  HISTORY_WINDOW_UNITS = { 's' => 1, 'm' => 60, 'h' => 3600, 'd' => 86_400 }.freeze
37
37
  DEFAULT_HISTORY_WINDOW = 24 * 3600
38
+ # Sidekiq Web's dashboard `?days=N` range (free §25.4).
39
+ MAX_HISTORY_DAYS = 180
40
+ # Far past any real set; bounds a `?cursor=` before it reaches LRANGE.
41
+ MAX_CURSOR = 1 << 40
38
42
 
39
43
  # Per-set action whitelists. Maps the SPA's action name to the
40
44
  # SortedEntry/JobSet method. Anything not listed 400s — keeps the bulk/
@@ -67,10 +71,12 @@ module Wurk
67
71
  }
68
72
  end
69
73
 
74
+ # `?direction=asc` lists oldest first, the job the next fetch takes at the
75
+ # top, as Sidekiq Web's queue page does (free §25.4).
70
76
  def queue
71
77
  q = ::Wurk::Queue.new(params[:name].to_s)
72
78
  page = ::Wurk::Api::Pagination.window(params)
73
- gauges, jobs = queue_page(q, page)
79
+ gauges, jobs = queue_page(q, page, params[:direction].to_s == 'asc')
74
80
  render json: {
75
81
  name: q.name, size: gauges.size, latency: gauges.latency, paused: gauges.paused?,
76
82
  **::Wurk::Api::Pagination.meta(page), jobs: jobs
@@ -121,6 +127,8 @@ module Wurk
121
127
 
122
128
  def retries_all
123
129
  set = ::Wurk::RetrySet.new
130
+ return sweep_matching(set, RETRY_ACTIONS) if filtered_sweep?
131
+
124
132
  count = case params[:cmd].to_s
125
133
  when 'retry' then set.retry_all
126
134
  when 'kill' then set.kill_all
@@ -136,6 +144,8 @@ module Wurk
136
144
 
137
145
  def scheduled_all
138
146
  set = ::Wurk::ScheduledSet.new
147
+ return sweep_matching(set, SCHEDULED_ACTIONS) if filtered_sweep?
148
+
139
149
  case params[:cmd].to_s
140
150
  when 'delete' then render json: { ok: true, count: clear_set(set) }
141
151
  when 'add_to_queue' then drain_set(set, :add_to_queue)
@@ -149,6 +159,8 @@ module Wurk
149
159
 
150
160
  def dead_all
151
161
  set = ::Wurk::DeadSet.new
162
+ return sweep_matching(set, DEAD_ACTIONS) if filtered_sweep?
163
+
152
164
  count = case params[:cmd].to_s
153
165
  when 'retry' then set.retry_all
154
166
  when 'delete' then clear_set(set)
@@ -179,11 +191,13 @@ module Wurk
179
191
 
180
192
  # Rows are Batch::Status#summary: #data with the failed and dead jid sets
181
193
  # counted rather than listed. GET /api/batches/:bid carries the jids.
194
+ # `?dead=1` lists `dead-batches` instead (Pro's Dead batches tab);
195
+ # `?tag=` narrows either to the batches carrying that tag, and takes the
196
+ # place of `?substr=` (BatchSet#tagged_snapshot).
182
197
  def batches
183
198
  page = ::Wurk::Api::Pagination.window(params)
184
- total, rows = page_rows(::Wurk::BatchSet.new, page, :summary.to_proc) do |summary|
185
- summary.transform_keys(&:to_sym)
186
- end
199
+ set = %w[1 true].include?(params[:dead].to_s) ? ::Wurk::Batch::DeadSet.new : ::Wurk::BatchSet.new
200
+ total, rows = batch_rows(set, page, params[:tag].to_s)
187
201
  render json: { total: total, **::Wurk::Api::Pagination.meta(page), batches: rows }
188
202
  end
189
203
 
@@ -284,10 +298,11 @@ module Wurk
284
298
  end
285
299
 
286
300
  # Cluster-total throughput/failures time-series for the dashboard charts.
287
- # `:bucket` is 1m/5m/1h; `?window=24h` (s/m/h/d suffix) is clamped to the
288
- # bucket's retention. Chart-ready array under `series`.
301
+ # `:bucket` is 1m/5m/1h; `?window=24h` (s/m/h/d suffix) or `?days=N`
302
+ # (1..180, wins over window) is clamped to the bucket's retention.
303
+ # Chart-ready array under `series`.
289
304
  def history
290
- window = parse_window(params[:window])
305
+ window = history_window(params)
291
306
  series = ::Wurk::Web::Enterprise::Historical.history(params[:bucket].to_s, window: window)
292
307
  render json: { bucket: params[:bucket].to_s, window: window, series: series.map { |row| ::Wurk::Api::Serializers.history_point(row) } }
293
308
  rescue ::ArgumentError => e
@@ -307,10 +322,10 @@ module Wurk
307
322
 
308
323
  # Per-queue size/latency gauge time-series for the Metrics/Historical tab.
309
324
  # `:bucket` is 1m/5m/1h; `?window=24h` (s/m/h/d) is clamped to the bucket's
310
- # retention; optional `?queue=<name>` narrows to one queue. Each queue's
311
- # `points` are chart-ready.
325
+ # retention (`?days=N` as on #history); optional `?queue=<name>` narrows
326
+ # to one queue. Each queue's `points` are chart-ready.
312
327
  def queue_history # rubocop:disable Metrics/AbcSize
313
- window = parse_window(params[:window])
328
+ window = history_window(params)
314
329
  queues = params[:queue].present? ? [params[:queue].to_s] : nil
315
330
  series = ::Wurk::Web::Enterprise::Historical.queue_history(params[:bucket].to_s, window: window, queues: queues)
316
331
  render json: {
@@ -413,7 +428,7 @@ module Wurk
413
428
  return render(json: { error: 'unknown action' }, status: :bad_request) unless method
414
429
 
415
430
  keys = Array(params[:keys]).map(&:to_s).uniq
416
- # Each key costs a ZRANGEBYSCORE plus per-entry mutations; an uncapped
431
+ # Each key costs a pipelined ZRANGEBYSCORE plus per-entry mutations; an uncapped
417
432
  # list lets one POST issue tens of thousands of round-trips. The UI's
418
433
  # per-row selections accumulate across pages (toggleAll works against
419
434
  # the visible page's keys only) and the bulk POST sends the whole Set,
@@ -443,8 +458,8 @@ module Wurk
443
458
 
444
459
  # 422 when any entry failed, so the SPA's error toast fires; `count` is
445
460
  # what was applied either way.
446
- def render_applied(total, failures)
447
- body = { ok: failures.empty?, count: total - failures.size }
461
+ def render_applied(total, failures, extra = {})
462
+ body = { ok: failures.empty?, count: total - failures.size, **extra }
448
463
  return render(json: body) if failures.empty?
449
464
 
450
465
  render json: body.merge(failed: failures), status: 422
@@ -471,13 +486,50 @@ module Wurk
471
486
  # Maps "<score>|<jid>" keys to live SortedEntry objects via score-bracketed
472
487
  # fetch (exact float match, narrowed by jid) — avoids depending on float→
473
488
  # string round-tripping between JS and Ruby. Skips malformed/empty keys.
489
+ # One pipelined round trip for every key (JobSet#fetch_pairs).
474
490
  def entries_for(set, keys)
475
- keys.flat_map do |key|
491
+ pairs = keys.filter_map do |key|
476
492
  score, jid = key.to_s.split('|', 2)
477
- next [] if jid.nil? || jid.empty?
493
+ [score.to_f, jid] unless jid.nil? || jid.empty?
494
+ end
495
+ set.fetch_pairs(pairs)
496
+ end
497
+
498
+ def batch_rows(set, page, tag)
499
+ symbolize = ->(summary) { summary.transform_keys(&:to_sym) }
500
+ return page_rows(set, page, &symbolize) if tag.empty?
501
+
502
+ total, summaries = set.tagged_snapshot(tag, ::Wurk::Api::Pagination.offset(page), page[:count])
503
+ [total, summaries.map(&symbolize)]
504
+ end
505
+
506
+ def filtered_sweep? = !params[:substr].to_s.empty?
478
507
 
479
- set.fetch(score.to_f, jid)
508
+ # `<set>/all/:cmd?substr=`: applies `cmd` to the entries the same filtered
509
+ # listing shows, newest first, at most SWEEP_LIMIT of them within the
510
+ # filter's scan budget per request. The answer carries `done` (the walk
511
+ # reached the end of the set) and `cursor`, the raw offset to send back as
512
+ # `?cursor=` to carry on: the rows examined minus those this request moved
513
+ # out of the set. Entries added or removed meanwhile above that offset
514
+ # shift it, so a resumed sweep can re-examine or skip a few rows.
515
+ def sweep_matching(set, actions)
516
+ method = actions[params[:cmd].to_s]
517
+ return render(json: { error: 'unknown action' }, status: :bad_request) unless method
518
+
519
+ entries, scanned_to, done = matching_entries(set)
520
+ failures = apply_each(entries, method)
521
+ cursor = scanned_to - (entries.size - failures.size)
522
+ render_applied(entries.size, failures, matched: entries.size, done: done, cursor: cursor)
523
+ end
524
+
525
+ # [the matches from `?cursor=`, the raw offset the walk stopped at, done].
526
+ def matching_entries(set)
527
+ from = ::Wurk::Api::Pagination.clamp_int(params[:cursor], 0, MAX_CURSOR, 0)
528
+ rows = ::Wurk::Api::Pagination.walk(from) { |offset, count| set.snapshot(offset, count).last }
529
+ entries, examined, done = ::Wurk::Api::Pagination.matching(rows, params[:substr].to_s) do |entry|
530
+ ::Wurk::Api::Serializers.sorted_entry(entry)
480
531
  end
532
+ [entries, from + examined, done]
481
533
  end
482
534
 
483
535
  # UNLINKs the whole set, returning the count removed (read before clearing
@@ -507,26 +559,36 @@ module Wurk
507
559
 
508
560
  # [total, rows] of one listing page. Unfiltered, the page is read straight
509
561
  # off Redis at its offset (the set's #snapshot), so page 999 costs what
510
- # page 0 does; a filter counts matching rows, so it still walks, bounded by
511
- # FILTER_SCAN_LIMIT. `walk` maps a walked member to what #snapshot yields
512
- # (a Batch::Status to its summary); the block serializes either.
513
- def page_rows(set, page, walk = nil, &serialize)
562
+ # page 0 does; a filter counts matching rows, so it walks the set through
563
+ # the same #snapshot, bounded by FILTER_SCAN_LIMIT.
564
+ def page_rows(set, page, &)
514
565
  if page[:substr].empty?
515
566
  total, members = set.snapshot(::Wurk::Api::Pagination.offset(page), page[:count])
516
- return [total, members.map(&serialize)]
567
+ return [total, members.map(&)]
517
568
  end
518
569
 
519
- rows = ::Wurk::Api::Pagination.slice(set, page) { |member| serialize.call(walk ? walk.call(member) : member) }
520
- [set.size, rows]
570
+ rows = ::Wurk::Api::Pagination.walk { |offset, count| set.snapshot(offset, count).last }
571
+ [set.size, ::Wurk::Api::Pagination.slice(rows, page, &)]
521
572
  end
522
573
 
523
574
  # The gauges (anything answering size/latency/paused?) and the page's rows.
524
- def queue_page(queue, page)
575
+ def queue_page(queue, page, oldest_first)
525
576
  serialize = ->(rec) { ::Wurk::Api::Serializers.job_record(rec) }
526
- return [queue, ::Wurk::Api::Pagination.slice(queue, page, &serialize)] unless page[:substr].empty?
577
+ unless page[:substr].empty?
578
+ rows = ::Wurk::Api::Pagination.walk { |offset, count| queue_records(queue, offset, count, oldest_first).last }
579
+ return [queue, ::Wurk::Api::Pagination.slice(rows, page, &serialize)]
580
+ end
581
+
582
+ snapshot, records = queue_records(queue, ::Wurk::Api::Pagination.offset(page), page[:count], oldest_first)
583
+ [snapshot, records.map(&serialize)]
584
+ end
527
585
 
528
- snapshot = queue.snapshot(::Wurk::Api::Pagination.offset(page), page[:count])
529
- [snapshot, snapshot.records.map(&serialize)]
586
+ # [snapshot, its records in listing order]. Oldest first reads the same
587
+ # LRANGE from the tail: negative indexes `-(offset + count)..-(offset + 1)`,
588
+ # which Redis clamps at the head, then reversed.
589
+ def queue_records(queue, offset, count, oldest_first)
590
+ snapshot = queue.snapshot(oldest_first ? -(offset + count) : offset, count)
591
+ [snapshot, oldest_first ? snapshot.records.reverse : snapshot.records]
530
592
  end
531
593
 
532
594
  def render_sorted_entry(set)
@@ -552,6 +614,13 @@ module Wurk
552
614
  )
553
615
  end
554
616
 
617
+ # `?days=N` (1..MAX_HISTORY_DAYS) in seconds when it parses, else
618
+ # `?window=`.
619
+ def history_window(params)
620
+ days = ::Wurk::Api::Pagination.clamp_int(params[:days], 1, MAX_HISTORY_DAYS, nil)
621
+ days ? days * HISTORY_WINDOW_UNITS.fetch('d') : parse_window(params[:window])
622
+ end
623
+
555
624
  # Resolves the per-class metrics window. `minutes:` wins when present;
556
625
  # `hours:` is used otherwise; default falls back to 60 minutes so callers
557
626
  # that pass neither still get a useful series.
@@ -38,6 +38,12 @@ module Wurk
38
38
  # pre-paint script reads it, and that script runs before the stylesheet so
39
39
  # a host default never flashes the other palette.
40
40
  HEAD_OPEN = '<head>'
41
+ # The built shell's asset URLs: Vite builds with a relative `base`
42
+ # (frontend/vite.config.ts) so the bundle's own chunk and font URLs resolve
43
+ # against wherever it is served from; only the shell needs an absolute
44
+ # prefix, because it is served from the page URL, not the asset mount.
45
+ RELATIVE_ASSET_URL = %r{(["'])\./}
46
+ SCRIPT_OPEN = '<script'
41
47
 
42
48
  def index
43
49
  render layout: false, html: decorate_shell(spa_html).html_safe
@@ -46,7 +52,18 @@ module Wurk
46
52
  private
47
53
 
48
54
  def decorate_shell(html)
49
- inject_theme_default(inject_locale_hint(inject_head(html)))
55
+ stamp_csp_nonce(inject_theme_default(inject_locale_hint(inject_head(html))))
56
+ end
57
+
58
+ # A host policy with a nonce generator (`script-src 'self' 'nonce-…'`)
59
+ # refuses every inline script without the request's nonce, and the shell
60
+ # cannot run without its injected mount base. Every <script> gets it, the
61
+ # external module included, so a `'strict-dynamic'` policy loads it too.
62
+ def stamp_csp_nonce(html)
63
+ nonce = request.content_security_policy_nonce
64
+ return html unless nonce
65
+
66
+ html.gsub(SCRIPT_OPEN) { %(#{SCRIPT_OPEN} nonce="#{::ERB::Util.html_escape(nonce)}") }
50
67
  end
51
68
 
52
69
  def spa_html
@@ -143,7 +160,14 @@ module Wurk
143
160
  raise "Wurk dashboard: precompiled SPA index.html missing at #{path}. " \
144
161
  'Run `bin/rake frontend:build`.'
145
162
  end
146
- path.read
163
+ path.read.gsub(RELATIVE_ASSET_URL) { "#{::Regexp.last_match(1)}#{asset_base}/" }
164
+ end
165
+
166
+ # AssetMount sits in the host's stack, so its URL carries the host's own
167
+ # prefix (RAILS_RELATIVE_URL_ROOT, or a proxy's SCRIPT_NAME), not the
168
+ # engine mount: `/app/wurk` serves its assets from `/app/wurk-assets`.
169
+ def asset_base
170
+ "#{request.get_header('ORIGINAL_SCRIPT_NAME').to_s.chomp('/')}#{::Wurk::Engine::AssetMount::PREFIX}"
147
171
  end
148
172
  end
149
173
  end
@@ -6,16 +6,21 @@ require 'uri'
6
6
  module Wurk
7
7
  # Profiles pane non-JSON endpoints (spec §25.4):
8
8
  #
9
- # GET /profiles/:key/data → the stored gzipped gecko JSON, streamed with a
9
+ # GET /profiles/:key/data → the stored gzipped gecko JSON, streamed with a
10
10
  # gzip Content-Encoding (Firefox profiler pulls
11
11
  # this when given a `from-url` source).
12
- # GET /profiles/:key → upload the profile to the Firefox profiler
12
+ # POST /profiles/:key → upload the profile to the Firefox profiler
13
13
  # store and 302 to its public view URL.
14
+ # GET /profiles/:key → 302 to an upload already made (by either UI),
15
+ # 405 when there is none yet.
16
+ #
17
+ # Sidekiq uploads on the GET. Sending job data to a third party is a side
18
+ # effect, so here only a POST does it: SameOriginGuard covers it like every
19
+ # other mutation, and read-only mode refuses it (#101 W5).
14
20
  #
15
21
  # `:key` is "<token>-<jid>". The JSON list lives at /api/profiles.
16
22
  class ProfilesController < ApplicationController
17
- # CSRF protection is for state-changing form posts; these are GET reads.
18
- skip_forgery_protection
23
+ include SameOriginGuard
19
24
 
20
25
  def data
21
26
  blob = profile_blob(params[:key])
@@ -26,36 +31,36 @@ module Wurk
26
31
  end
27
32
 
28
33
  def show
29
- # GET-shaped for Sidekiq parity, but uploading the profile to the public
30
- # Firefox profiler store is a side effect — read-only deploys (e.g. the
31
- # public demo) must not let any visitor exfiltrate profiling data.
32
34
  return head(:forbidden) if ::Wurk::Web.config.read_only?
33
- return head(:forbidden) unless navigated_from_dashboard?
34
35
 
36
+ sid = cached_sid(params[:key])
37
+ return redirect_to_profile(sid) if sid
38
+ return head(:not_found) unless profile_exists?(params[:key])
39
+
40
+ response.headers['Allow'] = 'POST'
41
+ head :method_not_allowed
42
+ end
43
+
44
+ # Read-only mode 403s this POST in Wurk::Web::Authorization, before it
45
+ # gets here.
46
+ def upload
35
47
  sid = profile_sid(params[:key])
36
48
  return head(:not_found) if sid == :missing
37
49
  return head(:bad_gateway) unless sid
38
50
 
39
- redirect_to(format(::Wurk::Web.config.profile_view_url, sid), allow_other_host: true)
51
+ redirect_to_profile(sid)
40
52
  end
41
53
 
42
54
  private
43
55
 
44
- # The upload is a side effect behind a GET, so a cross-site `<img src>`
45
- # could trigger it with the operator's session. Allow the dashboard's own
46
- # link (same-origin) and a typed URL or bookmark (`none`). A browser too
47
- # old to send Sec-Fetch-Site still sends a Referer, which must then be
48
- # this host.
49
- def navigated_from_dashboard?
50
- site = request.headers['Sec-Fetch-Site']
51
- return %w[same-origin none].include?(site) if site
52
-
53
- referer = URI.parse(request.referer.to_s)
54
- referer.host == request.host && referer.port == request.port
55
- rescue URI::InvalidURIError
56
- false
56
+ def redirect_to_profile(sid)
57
+ redirect_to(format(::Wurk::Web.config.profile_view_url, sid), allow_other_host: true)
57
58
  end
58
59
 
60
+ def profile_exists?(key) = ::Wurk.redis { |c| c.call('EXISTS', key) }.positive?
61
+
62
+ def cached_sid(key) = ::Wurk.redis { |c| c.call('HGET', key, 'sid') }
63
+
59
64
  def profile_blob(key)
60
65
  ::Wurk::ProfileRecord.data_for(key)
61
66
  end
@@ -64,7 +69,7 @@ module Wurk
64
69
  # upload exactly as Sidekiq's Web UI does, so either UI reuses the other's
65
70
  # upload. :missing when the profile is gone, nil when the upload failed.
66
71
  def profile_sid(key)
67
- sid = ::Wurk.redis { |c| c.call('HGET', key, 'sid') }
72
+ sid = cached_sid(key)
68
73
  return sid if sid
69
74
 
70
75
  blob = profile_blob(key)
data/config/routes.rb CHANGED
@@ -126,12 +126,14 @@ Wurk::Engine.routes.draw do
126
126
  mount Wurk::API => Wurk::API::ENGINE_MOUNT, constraints: ->(request) { Wurk::API.serves?(request.path_info) }
127
127
 
128
128
  # Profiles (v8.0+) — not under /api: `:key/data` streams the gzipped gecko
129
- # blob with a gzip Content-Encoding, and `:key` POST-uploads the profile to
130
- # the Firefox profiler then 302s to its public view. `:key` is "<token>-<jid>".
131
- # The `/data` route is declared first so it wins over the bare `:key` match.
132
- # Spec: docs/target/sidekiq-free.md §25.4.
133
- get 'profiles/:key/data', to: 'profiles#data', as: :profile_data, constraints: { key: %r{[^/]+} }
134
- get 'profiles/:key', to: 'profiles#show', as: :profile, constraints: { key: %r{[^/]+} }
129
+ # blob with a gzip Content-Encoding; `POST :key` uploads the profile to the
130
+ # Firefox profiler then 302s to its public view, and `GET :key` only follows
131
+ # an upload already made (Sidekiq uploads on the GET; #101 W5). `:key` is
132
+ # "<token>-<jid>". The `/data` route is declared first so it wins over the
133
+ # bare `:key` match. Spec: docs/target/sidekiq-free.md §25.4.
134
+ get 'profiles/:key/data', to: 'profiles#data', as: :profile_data, constraints: { key: %r{[^/]+} }
135
+ get 'profiles/:key', to: 'profiles#show', as: :profile, constraints: { key: %r{[^/]+} }
136
+ post 'profiles/:key', to: 'profiles#upload', as: :profile_upload, constraints: { key: %r{[^/]+} }
135
137
 
136
138
  # Third-party Web extensions (#187): server-rendered route + assets. The SPA's
137
139
  # Extension page fetches `ext/:name/<subpath>` and embeds the returned HTML;