wurk 1.17.0 → 1.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (204) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/lib/sidekiq/cron/web.rb +10 -0
  4. data/lib/sidekiq/cron.rb +10 -0
  5. data/lib/sidekiq-cron.rb +11 -0
  6. data/lib/wurk/batch/server_middleware.rb +3 -3
  7. data/lib/wurk/boot_checks.rb +8 -6
  8. data/lib/wurk/compat.rb +19 -15
  9. data/lib/wurk/component.rb +1 -0
  10. data/lib/wurk/fetcher/private_list_key.rb +40 -8
  11. data/lib/wurk/fetcher/reaper.rb +12 -4
  12. data/lib/wurk/fetcher/unparseable_keys.rb +8 -9
  13. data/lib/wurk/finished_job_cleanup.rb +156 -0
  14. data/lib/wurk/job_retry.rb +2 -10
  15. data/lib/wurk/launcher.rb +15 -4
  16. data/lib/wurk/lua/unique_jobs_delete.lua +5 -0
  17. data/lib/wurk/lua/unique_jobs_delete_by_digest.lua +6 -0
  18. data/lib/wurk/lua/unique_jobs_delete_job_by_digest.lua +42 -0
  19. data/lib/wurk/lua/unique_jobs_lock.lua +54 -0
  20. data/lib/wurk/lua/unique_jobs_queue.lua +43 -0
  21. data/lib/wurk/lua/unique_jobs_queue_and_lock.lua +67 -0
  22. data/lib/wurk/lua/unique_jobs_unlock.lua +61 -0
  23. data/lib/wurk/preflight/checks.rb +6 -5
  24. data/lib/wurk/processor.rb +26 -47
  25. data/lib/wurk/redis_pool.rb +16 -1
  26. data/lib/wurk/rspec.rb +246 -0
  27. data/lib/wurk/sidekiq_cron/arguments.rb +69 -0
  28. data/lib/wurk/sidekiq_cron/configuration.rb +43 -0
  29. data/lib/wurk/sidekiq_cron/job/enqueue.rb +142 -0
  30. data/lib/wurk/sidekiq_cron/job/store.rb +130 -0
  31. data/lib/wurk/sidekiq_cron/job.rb +292 -0
  32. data/lib/wurk/sidekiq_cron/namespace.rb +52 -0
  33. data/lib/wurk/sidekiq_cron/poller.rb +71 -0
  34. data/lib/wurk/sidekiq_cron/schedule.rb +114 -0
  35. data/lib/wurk/sidekiq_cron/schedule_loader.rb +50 -0
  36. data/lib/wurk/sidekiq_cron/web_rows.rb +55 -0
  37. data/lib/wurk/sidekiq_cron.rb +52 -0
  38. data/lib/wurk/unique_jobs/api_extension.rb +84 -0
  39. data/lib/wurk/unique_jobs/config.rb +75 -0
  40. data/lib/wurk/unique_jobs/constants.rb +53 -0
  41. data/lib/wurk/unique_jobs/digests.rb +169 -0
  42. data/lib/wurk/unique_jobs/errors.rb +71 -0
  43. data/lib/wurk/unique_jobs/job.rb +226 -0
  44. data/lib/wurk/unique_jobs/lock.rb +345 -0
  45. data/lib/wurk/unique_jobs/locksmith.rb +240 -0
  46. data/lib/wurk/unique_jobs/middleware.rb +109 -0
  47. data/lib/wurk/unique_jobs/on_conflict.rb +107 -0
  48. data/lib/wurk/unique_jobs/orphans.rb +258 -0
  49. data/lib/wurk/unique_jobs/reflections.rb +72 -0
  50. data/lib/wurk/unique_jobs/require/sidekiq-unique-jobs.rb +6 -0
  51. data/lib/wurk/unique_jobs/require/sidekiq_unique_jobs/web.rb +8 -0
  52. data/lib/wurk/unique_jobs/require/sidekiq_unique_jobs.rb +5 -0
  53. data/lib/wurk/unique_jobs/sidekiq_unique_jobs.rb +15 -0
  54. data/lib/wurk/unique_jobs/web/views/_paging.erb +10 -0
  55. data/lib/wurk/unique_jobs/web/views/changelogs.erb +62 -0
  56. data/lib/wurk/unique_jobs/web/views/lock.erb +110 -0
  57. data/lib/wurk/unique_jobs/web/views/locks.erb +61 -0
  58. data/lib/wurk/unique_jobs/web.rb +150 -0
  59. data/lib/wurk/unique_jobs.rb +142 -0
  60. data/lib/wurk/unique_jobs_compat/private_list_digests.rb +121 -0
  61. data/lib/wurk/unique_jobs_compat.rb +128 -0
  62. data/lib/wurk/version.rb +1 -1
  63. data/lib/wurk/web/dashboard/api_actions.rb +1 -2
  64. data/lib/wurk/web/enterprise.rb +23 -0
  65. data/lib/wurk.rb +4 -1
  66. data/vendor/assets/dashboard/assets/{ArgsValue-s6SvnYnn.js → ArgsValue-8zbIUK63.js} +1 -1
  67. data/vendor/assets/dashboard/assets/ArgsValue-8zbIUK63.js.br +0 -0
  68. data/vendor/assets/dashboard/assets/ArgsValue-8zbIUK63.js.gz +0 -0
  69. data/vendor/assets/dashboard/assets/{BatchDetail-CprIJHVF.js → BatchDetail-B7FnhWOm.js} +1 -1
  70. data/vendor/assets/dashboard/assets/BatchDetail-B7FnhWOm.js.br +0 -0
  71. data/vendor/assets/dashboard/assets/BatchDetail-B7FnhWOm.js.gz +0 -0
  72. data/vendor/assets/dashboard/assets/{Batches-_UtmkdcL.js → Batches-KBN4rVe3.js} +1 -1
  73. data/vendor/assets/dashboard/assets/Batches-KBN4rVe3.js.br +0 -0
  74. data/vendor/assets/dashboard/assets/Batches-KBN4rVe3.js.gz +0 -0
  75. data/vendor/assets/dashboard/assets/{Busy-CxUt_KaT.js → Busy-Gz7qEa1m.js} +1 -1
  76. data/vendor/assets/dashboard/assets/Busy-Gz7qEa1m.js.br +0 -0
  77. data/vendor/assets/dashboard/assets/Busy-Gz7qEa1m.js.gz +0 -0
  78. data/vendor/assets/dashboard/assets/Cron-B8esPvHL.js +1 -0
  79. data/vendor/assets/dashboard/assets/Cron-B8esPvHL.js.br +0 -0
  80. data/vendor/assets/dashboard/assets/Cron-B8esPvHL.js.gz +0 -0
  81. data/vendor/assets/dashboard/assets/{Dashboard-BpeXrgWN.js → Dashboard-BfVW4Db7.js} +1 -1
  82. data/vendor/assets/dashboard/assets/Dashboard-BfVW4Db7.js.br +0 -0
  83. data/vendor/assets/dashboard/assets/Dashboard-BfVW4Db7.js.gz +0 -0
  84. data/vendor/assets/dashboard/assets/{Dead-DxG8m9Ea.js → Dead-i929U3Al.js} +1 -1
  85. data/vendor/assets/dashboard/assets/Dead-i929U3Al.js.br +0 -0
  86. data/vendor/assets/dashboard/assets/Dead-i929U3Al.js.gz +0 -0
  87. data/vendor/assets/dashboard/assets/{Extension-Bdw1AWK9.js → Extension-DtT_BQGI.js} +1 -1
  88. data/vendor/assets/dashboard/assets/Extension-DtT_BQGI.js.br +0 -0
  89. data/vendor/assets/dashboard/assets/Extension-DtT_BQGI.js.gz +0 -0
  90. data/vendor/assets/dashboard/assets/{FlowDetail-BbLiOUVq.js → FlowDetail-dSxWLJwW.js} +1 -1
  91. data/vendor/assets/dashboard/assets/FlowDetail-dSxWLJwW.js.br +0 -0
  92. data/vendor/assets/dashboard/assets/FlowDetail-dSxWLJwW.js.gz +0 -0
  93. data/vendor/assets/dashboard/assets/{Flows-Cdh5HxbD.js → Flows-DBXdrnl_.js} +1 -1
  94. data/vendor/assets/dashboard/assets/Flows-DBXdrnl_.js.br +0 -0
  95. data/vendor/assets/dashboard/assets/Flows-DBXdrnl_.js.gz +0 -0
  96. data/vendor/assets/dashboard/assets/{JobDetailModal-DyrUaaGZ.js → JobDetailModal-wz97ZwuO.js} +1 -1
  97. data/vendor/assets/dashboard/assets/JobDetailModal-wz97ZwuO.js.br +0 -0
  98. data/vendor/assets/dashboard/assets/JobDetailModal-wz97ZwuO.js.gz +0 -0
  99. data/vendor/assets/dashboard/assets/{Limiters-D7r6cfSD.js → Limiters-LLzkwl5z.js} +1 -1
  100. data/vendor/assets/dashboard/assets/Limiters-LLzkwl5z.js.br +0 -0
  101. data/vendor/assets/dashboard/assets/Limiters-LLzkwl5z.js.gz +0 -0
  102. data/vendor/assets/dashboard/assets/{Metrics-BLenaRy4.js → Metrics-C0ilxg59.js} +1 -1
  103. data/vendor/assets/dashboard/assets/Metrics-C0ilxg59.js.br +0 -0
  104. data/vendor/assets/dashboard/assets/Metrics-C0ilxg59.js.gz +0 -0
  105. data/vendor/assets/dashboard/assets/{NotFound-P0HnKG_i.js → NotFound-CHPpvK-n.js} +1 -1
  106. data/vendor/assets/dashboard/assets/NotFound-CHPpvK-n.js.br +0 -0
  107. data/vendor/assets/dashboard/assets/NotFound-CHPpvK-n.js.gz +0 -0
  108. data/vendor/assets/dashboard/assets/{PageHeader-Dr0x5uFD.js → PageHeader-CGep_jFP.js} +1 -1
  109. data/vendor/assets/dashboard/assets/PageHeader-CGep_jFP.js.br +0 -0
  110. data/vendor/assets/dashboard/assets/PageHeader-CGep_jFP.js.gz +0 -0
  111. data/vendor/assets/dashboard/assets/{Profiles-DwBcuGsp.js → Profiles-D_59KJVX.js} +1 -1
  112. data/vendor/assets/dashboard/assets/Profiles-D_59KJVX.js.br +0 -0
  113. data/vendor/assets/dashboard/assets/Profiles-D_59KJVX.js.gz +0 -0
  114. data/vendor/assets/dashboard/assets/{Queues-BpB_QfMT.js → Queues-B84cTtnr.js} +1 -1
  115. data/vendor/assets/dashboard/assets/Queues-B84cTtnr.js.br +0 -0
  116. data/vendor/assets/dashboard/assets/Queues-B84cTtnr.js.gz +0 -0
  117. data/vendor/assets/dashboard/assets/{RefreshError-CFF9cD72.js → RefreshError-LAOkINDS.js} +1 -1
  118. data/vendor/assets/dashboard/assets/RefreshError-LAOkINDS.js.br +2 -0
  119. data/vendor/assets/dashboard/assets/RefreshError-LAOkINDS.js.gz +0 -0
  120. data/vendor/assets/dashboard/assets/{Retries-CvpBa3nA.js → Retries-sdTIe5PU.js} +1 -1
  121. data/vendor/assets/dashboard/assets/Retries-sdTIe5PU.js.br +0 -0
  122. data/vendor/assets/dashboard/assets/Retries-sdTIe5PU.js.gz +0 -0
  123. data/vendor/assets/dashboard/assets/{Scheduled-B5_rNwmD.js → Scheduled-mWorUG81.js} +1 -1
  124. data/vendor/assets/dashboard/assets/Scheduled-mWorUG81.js.br +0 -0
  125. data/vendor/assets/dashboard/assets/Scheduled-mWorUG81.js.gz +0 -0
  126. data/vendor/assets/dashboard/assets/{Search-DBiXXQ1X.js → Search-DQg2ky9F.js} +1 -1
  127. data/vendor/assets/dashboard/assets/Search-DQg2ky9F.js.br +0 -0
  128. data/vendor/assets/dashboard/assets/Search-DQg2ky9F.js.gz +0 -0
  129. data/vendor/assets/dashboard/assets/{charts-BowrQgy3.js → charts-D2ZSzfcT.js} +1 -1
  130. data/vendor/assets/dashboard/assets/charts-D2ZSzfcT.js.br +0 -0
  131. data/vendor/assets/dashboard/assets/charts-D2ZSzfcT.js.gz +0 -0
  132. data/vendor/assets/dashboard/assets/{index-lb7Hct36.js → index-CYxK_mMH.js} +2 -2
  133. data/vendor/assets/dashboard/assets/index-CYxK_mMH.js.br +0 -0
  134. data/vendor/assets/dashboard/assets/index-CYxK_mMH.js.gz +0 -0
  135. data/vendor/assets/dashboard/assets/{useJobSetList-DOJEPjtn.js → useJobSetList-Bq8gXURX.js} +1 -1
  136. data/vendor/assets/dashboard/assets/useJobSetList-Bq8gXURX.js.br +0 -0
  137. data/vendor/assets/dashboard/assets/useJobSetList-Bq8gXURX.js.gz +0 -0
  138. data/vendor/assets/dashboard/assets/{useResetPageOnEmpty-BkhAVjcM.js → useResetPageOnEmpty-DBe-fKXL.js} +1 -1
  139. data/vendor/assets/dashboard/assets/useResetPageOnEmpty-DBe-fKXL.js.br +0 -0
  140. data/vendor/assets/dashboard/assets/useResetPageOnEmpty-DBe-fKXL.js.gz +0 -0
  141. data/vendor/assets/dashboard/assets/{useSort-BH4O54LC.js → useSort-CB33x7jI.js} +1 -1
  142. data/vendor/assets/dashboard/assets/useSort-CB33x7jI.js.br +2 -0
  143. data/vendor/assets/dashboard/assets/useSort-CB33x7jI.js.gz +0 -0
  144. data/vendor/assets/dashboard/assets/{utils-5e3YBxoh.js → utils-DvEdG1B-.js} +1 -1
  145. data/vendor/assets/dashboard/assets/utils-DvEdG1B-.js.br +0 -0
  146. data/vendor/assets/dashboard/assets/utils-DvEdG1B-.js.gz +0 -0
  147. data/vendor/assets/dashboard/index.html +1 -1
  148. data/vendor/assets/dashboard/wurk-manifest.json +2 -2
  149. metadata +129 -82
  150. data/vendor/assets/dashboard/assets/ArgsValue-s6SvnYnn.js.br +0 -0
  151. data/vendor/assets/dashboard/assets/ArgsValue-s6SvnYnn.js.gz +0 -0
  152. data/vendor/assets/dashboard/assets/BatchDetail-CprIJHVF.js.br +0 -0
  153. data/vendor/assets/dashboard/assets/BatchDetail-CprIJHVF.js.gz +0 -0
  154. data/vendor/assets/dashboard/assets/Batches-_UtmkdcL.js.br +0 -0
  155. data/vendor/assets/dashboard/assets/Batches-_UtmkdcL.js.gz +0 -0
  156. data/vendor/assets/dashboard/assets/Busy-CxUt_KaT.js.br +0 -0
  157. data/vendor/assets/dashboard/assets/Busy-CxUt_KaT.js.gz +0 -0
  158. data/vendor/assets/dashboard/assets/Cron-BO4CLzcL.js +0 -1
  159. data/vendor/assets/dashboard/assets/Cron-BO4CLzcL.js.br +0 -0
  160. data/vendor/assets/dashboard/assets/Cron-BO4CLzcL.js.gz +0 -0
  161. data/vendor/assets/dashboard/assets/Dashboard-BpeXrgWN.js.br +0 -0
  162. data/vendor/assets/dashboard/assets/Dashboard-BpeXrgWN.js.gz +0 -0
  163. data/vendor/assets/dashboard/assets/Dead-DxG8m9Ea.js.br +0 -0
  164. data/vendor/assets/dashboard/assets/Dead-DxG8m9Ea.js.gz +0 -0
  165. data/vendor/assets/dashboard/assets/Extension-Bdw1AWK9.js.br +0 -0
  166. data/vendor/assets/dashboard/assets/Extension-Bdw1AWK9.js.gz +0 -0
  167. data/vendor/assets/dashboard/assets/FlowDetail-BbLiOUVq.js.br +0 -0
  168. data/vendor/assets/dashboard/assets/FlowDetail-BbLiOUVq.js.gz +0 -0
  169. data/vendor/assets/dashboard/assets/Flows-Cdh5HxbD.js.br +0 -0
  170. data/vendor/assets/dashboard/assets/Flows-Cdh5HxbD.js.gz +0 -0
  171. data/vendor/assets/dashboard/assets/JobDetailModal-DyrUaaGZ.js.br +0 -0
  172. data/vendor/assets/dashboard/assets/JobDetailModal-DyrUaaGZ.js.gz +0 -0
  173. data/vendor/assets/dashboard/assets/Limiters-D7r6cfSD.js.br +0 -0
  174. data/vendor/assets/dashboard/assets/Limiters-D7r6cfSD.js.gz +0 -0
  175. data/vendor/assets/dashboard/assets/Metrics-BLenaRy4.js.br +0 -0
  176. data/vendor/assets/dashboard/assets/Metrics-BLenaRy4.js.gz +0 -0
  177. data/vendor/assets/dashboard/assets/NotFound-P0HnKG_i.js.br +0 -0
  178. data/vendor/assets/dashboard/assets/NotFound-P0HnKG_i.js.gz +0 -0
  179. data/vendor/assets/dashboard/assets/PageHeader-Dr0x5uFD.js.br +0 -0
  180. data/vendor/assets/dashboard/assets/PageHeader-Dr0x5uFD.js.gz +0 -0
  181. data/vendor/assets/dashboard/assets/Profiles-DwBcuGsp.js.br +0 -0
  182. data/vendor/assets/dashboard/assets/Profiles-DwBcuGsp.js.gz +0 -0
  183. data/vendor/assets/dashboard/assets/Queues-BpB_QfMT.js.br +0 -0
  184. data/vendor/assets/dashboard/assets/Queues-BpB_QfMT.js.gz +0 -0
  185. data/vendor/assets/dashboard/assets/RefreshError-CFF9cD72.js.br +0 -0
  186. data/vendor/assets/dashboard/assets/RefreshError-CFF9cD72.js.gz +0 -0
  187. data/vendor/assets/dashboard/assets/Retries-CvpBa3nA.js.br +0 -0
  188. data/vendor/assets/dashboard/assets/Retries-CvpBa3nA.js.gz +0 -0
  189. data/vendor/assets/dashboard/assets/Scheduled-B5_rNwmD.js.br +0 -0
  190. data/vendor/assets/dashboard/assets/Scheduled-B5_rNwmD.js.gz +0 -0
  191. data/vendor/assets/dashboard/assets/Search-DBiXXQ1X.js.br +0 -0
  192. data/vendor/assets/dashboard/assets/Search-DBiXXQ1X.js.gz +0 -0
  193. data/vendor/assets/dashboard/assets/charts-BowrQgy3.js.br +0 -0
  194. data/vendor/assets/dashboard/assets/charts-BowrQgy3.js.gz +0 -0
  195. data/vendor/assets/dashboard/assets/index-lb7Hct36.js.br +0 -0
  196. data/vendor/assets/dashboard/assets/index-lb7Hct36.js.gz +0 -0
  197. data/vendor/assets/dashboard/assets/useJobSetList-DOJEPjtn.js.br +0 -0
  198. data/vendor/assets/dashboard/assets/useJobSetList-DOJEPjtn.js.gz +0 -0
  199. data/vendor/assets/dashboard/assets/useResetPageOnEmpty-BkhAVjcM.js.br +0 -0
  200. data/vendor/assets/dashboard/assets/useResetPageOnEmpty-BkhAVjcM.js.gz +0 -0
  201. data/vendor/assets/dashboard/assets/useSort-BH4O54LC.js.br +0 -0
  202. data/vendor/assets/dashboard/assets/useSort-BH4O54LC.js.gz +0 -0
  203. data/vendor/assets/dashboard/assets/utils-5e3YBxoh.js.br +0 -0
  204. data/vendor/assets/dashboard/assets/utils-5e3YBxoh.js.gz +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 21ea6463167ebec27cef785cfba9e726c5cd162feb8c735f54b7e971a442fec5
4
- data.tar.gz: 8be078d35ac16e090f004c3975035bec8b8eb545627e2bec7da1c2e979bc260f
3
+ metadata.gz: 0e76dc31e4cdd0cb170fb6d3882e01ce20596a4092938d87401eef04f26f30a0
4
+ data.tar.gz: 480f9e50d3a4360f23825b0cb6479e7ac4c3dda891a52c253731adf32ebe1ce6
5
5
  SHA512:
6
- metadata.gz: 1526cfaf774a77559de2aee1e82866c2be679fa2376ebd4f9d636a50a0947f64f4f100e69032c55fd3f10fc193f014c8f6b225cd17af738353a16edefbb9025b
7
- data.tar.gz: 2d6070c13fae762c34b2e868c51f31dc85985607fc4d533c311ba58ba22002a401344681e448b8548854bd053552ecf76ec97c02e74122eff0543e265ba93e9e
6
+ metadata.gz: f281b9e976f9c75961588a310f8544eed21e47bb835b3f31fec6155cd6dc4a670d04a15acc8bfbbaeaa0e55428c46aaf9375475c02891137ac090b54b27a5577
7
+ data.tar.gz: 200d2fa2e32212ba98e8f4c190f08791edda35a3308fe597830e8eea2c8863d3a60f29508799897d73e758891d1b6f20b5b096bd8dc9a8ac3b84c0ff71c72dc5
data/README.md CHANGED
@@ -308,7 +308,7 @@ Wurk is MIT and stays that way. If what you need is a commercial support contrac
308
308
 
309
309
  `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).
310
310
 
311
- **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.17.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.
311
+ **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.18.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.
312
312
 
313
313
  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.
314
314
 
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ # `require "sidekiq/cron/web"`. The gem's file registers the gem's tab when the
4
+ # gem is bundled. Native entries need no extension: the dashboard's own Cron
5
+ # page lists them beside the periodic loops (Wurk::SidekiqCron::WebRows).
6
+ if (spec = Gem.loaded_specs['sidekiq-cron'])
7
+ require File.join(spec.full_gem_path, 'lib/sidekiq/cron/web.rb')
8
+ else
9
+ require_relative '../../wurk/sidekiq_cron'
10
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ # `require "sidekiq/cron"`. With the sidekiq-cron gem in the bundle this is the
4
+ # gem's own file, whichever copy the load path finds first; without it, wurk's
5
+ # native implementation (lib/wurk/sidekiq_cron.rb) defines `Sidekiq::Cron`.
6
+ if (spec = Gem.loaded_specs['sidekiq-cron'])
7
+ require File.join(spec.full_gem_path, 'lib/sidekiq/cron.rb')
8
+ else
9
+ require_relative '../wurk/sidekiq_cron'
10
+ end
@@ -0,0 +1,11 @@
1
+ # rubocop:disable Naming/FileName -- the gem's own require name, hyphen included
2
+ # frozen_string_literal: true
3
+
4
+ # `require "sidekiq-cron"`, the gem's entrypoint (Bundler's auto-require).
5
+ # Bundled, the gem loads itself; otherwise wurk's native sidekiq-cron does.
6
+ if (spec = Gem.loaded_specs['sidekiq-cron'])
7
+ require File.join(spec.full_gem_path, 'lib/sidekiq-cron.rb')
8
+ else
9
+ require_relative 'wurk/sidekiq_cron'
10
+ end
11
+ # rubocop:enable Naming/FileName
@@ -23,9 +23,9 @@ module Wurk
23
23
  # The success ack runs outside the job's rescue: once `perform` returned,
24
24
  # nothing the batch bookkeeping raises may be mistaken for the job failing,
25
25
  # or a job that already did its work is retried and runs twice. The ack
26
- # itself is retried in-process and only raises (sending the job to retry,
27
- # at-least-once) when Redis stays unreachable — a jid left in the live set
28
- # would hold the batch open forever. The fire after it never raises: it is
26
+ # itself is retried in-process; when Redis stays unreachable it raises and
27
+ # the Processor hands the ack to FinishedJobCleanup, which sends it once
28
+ # Redis answers, without running the job again. The fire after it never raises: it is
29
29
  # re-driven in-process and then reported to the error handlers. Both wait
30
30
  # out a store that is not serving (Callbacks::STORE_OUTAGE_BUDGET): once
31
31
  # this job is ACKed nothing re-drives a fire that gave up.
@@ -69,17 +69,19 @@ module Wurk
69
69
  end
70
70
  end
71
71
 
72
- # Without the gem's middleware the option does nothing: the "unique" job
73
- # simply enqueues twice. Only classes the app has loaded by now are seen.
74
- def warn_on_ignored_locks(logger)
75
- return if defined?(::SidekiqUniqueJobs)
72
+ # Without a unique-jobs client middleware the option does nothing: the
73
+ # "unique" job simply enqueues twice. Either copy's counts, the gem's or
74
+ # Wurk's native one. Only classes the app has loaded by now are seen.
75
+ def warn_on_ignored_locks(logger, chain = Wurk.configuration.client_middleware)
76
+ return if UniqueJobsCompat.client_middleware?(chain)
76
77
 
77
78
  classes = locked_job_classes
78
79
  return if classes.empty?
79
80
 
80
81
  logger.warn do
81
- 'These jobs set `lock:` but sidekiq-unique-jobs is not loaded, so the option does nothing and ' \
82
- "duplicates will run: #{listing(classes)}. Keep the gem, or move them to `unique_for:`."
82
+ 'These jobs set `lock:` but no client middleware takes their locks, so the option does nothing and ' \
83
+ "duplicates will run: #{listing(classes)}. Add it once, in an initializer: " \
84
+ '`chain.add SidekiqUniqueJobs::Middleware::Client` (docs/unique-jobs.md).'
83
85
  end
84
86
  end
85
87
 
data/lib/wurk/compat.rb CHANGED
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Sidekiq aliases. This is the drop-in contract — every public Wurk::*
4
- # class is exposed under its Sidekiq::* name except two deliberate
5
- # exclusions, `Sidekiq::Cron` and `Sidekiq::Status` (#204): those namespaces
6
- # belong to the third-party sidekiq-cron / sidekiq-status gems, not to
7
- # Sidekiq itself. Never break the rest.
4
+ # class is exposed under its Sidekiq::* name except two namespaces that
5
+ # belong to third-party gems (#204): `Sidekiq::Status` is never defined, and
6
+ # `Sidekiq::Cron` is wurk's native sidekiq-cron only when that gem is not
7
+ # bundled. Never break the rest.
8
8
  #
9
9
  # Spec: docs/target/sidekiq-{free,pro,ent}.md.
10
10
 
@@ -17,13 +17,13 @@ require_relative 'loader'
17
17
  # {Wurk.configure_server}; `Sidekiq::Batch`, `Sidekiq::Limiter`,
18
18
  # `Sidekiq::Client`, `Sidekiq::Pro::Web`, `Sidekiq::Enterprise` all resolve to
19
19
  # their Wurk implementations. This alias surface is the drop-in contract and is
20
- # never broken. Two names are deliberately NOT aliased (#204): `Sidekiq::Cron`
21
- # and `Sidekiq::Status` — those namespaces belong to the third-party
22
- # sidekiq-cron / sidekiq-status gems. `sidekiq-cron` owns `Sidekiq::Cron`, and
23
- # squatting it made the gem's own Poller/Job classes collide at load;
24
- # `sidekiq-status` opens `module Sidekiq::Status`, which resolves the constant
25
- # instead of defining it, so the alias would hand the gem {Wurk::Status} to
26
- # reopen and clobber. The guard comments at `CronParser` and `Status` below
20
+ # never broken. Two names belong to third-party gems (#204): `Sidekiq::Cron`
21
+ # and `Sidekiq::Status`. `sidekiq-cron` owns `Sidekiq::Cron` when it is
22
+ # bundled — squatting it made the gem's own Poller/Job classes collide at
23
+ # load — so wurk's native one (Wurk::SidekiqCron) is only an autoload, and
24
+ # only when the gem is absent. `sidekiq-status` opens `module Sidekiq::Status`,
25
+ # which resolves the constant instead of defining it, so the alias would hand
26
+ # the gem {Wurk::Status} to reopen and clobber. The guard comments at `CronParser` and `Status` below
27
27
  # carry the full rationale.
28
28
  #
29
29
  # @example The same code targets Sidekiq or Wurk unchanged
@@ -175,10 +175,13 @@ module Sidekiq
175
175
  # and iterable_job.rb require subfiles that reopen the class before defining
176
176
  # it, which a direct require would turn into a circular one.
177
177
  #
178
- # No `Sidekiq::Cron` alias on purpose (#204): real Sidekiq never defines it
179
- # — that namespace belongs to the third-party sidekiq-cron gem, and squatting
180
- # it made the gem's own classes (Poller, Job) collide at load. Wurk's native
181
- # periodic surface is `Sidekiq::Periodic` (Ent parity) / `Wurk::Cron`.
178
+ # `Sidekiq::Cron` is not an alias (#204): real Sidekiq never defines it —
179
+ # that namespace belongs to the sidekiq-cron gem, and squatting it made the
180
+ # gem's own classes (Poller, Job) collide at load. With the gem bundled it is
181
+ # left alone. Without it, the name autoloads wurk's native sidekiq-cron
182
+ # (Wurk::SidekiqCron, lib/sidekiq/cron.rb), so an app that dropped the gem
183
+ # keeps its `Sidekiq::Cron::Job` calls and its Redis state. Wurk's Ent
184
+ # periodic surface is `Sidekiq::Periodic` / `Wurk::Cron`.
182
185
  #
183
186
  # `Flow` is a Wurk extra, not parity — aliased because nothing else claims
184
187
  # the name. Checked before adding it, the way `Sidekiq::Cron` (#204) and
@@ -199,6 +202,7 @@ module Sidekiq
199
202
  Deploy: 'compat/deploy', Encryption: 'compat/encryption'
200
203
  )
201
204
  Wurk::LazyLoader.register(Pro, Web: 'compat/web', BatchStatus: 'compat/web')
205
+ autoload :Cron, File.expand_path('../sidekiq/cron.rb', __dir__) unless Gem.loaded_specs.key?('sidekiq-cron')
202
206
 
203
207
  # Top-level Sidekiq.configure_server / configure_client / redis / logger
204
208
  # delegate to Wurk's class methods. Third-party gems treat these as the
@@ -170,6 +170,7 @@ module Wurk
170
170
  # `reraise: true` (used in tests / fail-fast boot). `oneshot: true`
171
171
  # clears the bucket after dispatch so the event can't fire twice.
172
172
  def fire_event(event, oneshot: true, reverse: false, reraise: false)
173
+ UniqueJobsCompat.install if event == :startup
173
174
  bucket = config[:lifecycle_events][event]
174
175
  return if bucket.nil? || bucket.empty?
175
176
 
@@ -4,19 +4,51 @@ require_relative '../keys'
4
4
 
5
5
  module Wurk
6
6
  class Fetcher
7
- # Reads the owner back out of a reliable-fetch private list key
8
- # (`queue:<public>|<host>|<pid>|<nonce>|<idx>`, see
9
- # Reliable.private_queue_name) for the Reaper's liveness check. Pure string
10
- # work, no Redis.
7
+ # Reads the owner back out of a reliable-fetch private list key for the
8
+ # Reaper's liveness check: Wurk's `queue:<public>|<host>|<pid>|<nonce>|<idx>`
9
+ # (Reliable.private_queue_name) or Sidekiq Pro's
10
+ # `queue:sq|<host>:<pid>:<nonce>|<public>` (SuperFetch#private_queue). Pure
11
+ # string work, no Redis.
11
12
  module PrivateListKey
12
13
  # The nonce shape Component::PROCESS_NONCE writes (`SecureRandom.hex(6)`).
13
14
  NONCE_PATTERN = /\A[0-9a-f]{12}\z/
14
15
 
16
+ PRO_PREFIX = "#{Keys::QUEUE_PREFIX}sq|".freeze
17
+ # Rebuilt byte for byte into the heartbeat key the liveness check reads,
18
+ # so a pid that would not round-trip through Integer is refused.
19
+ PRO_IDENTITY = /\A(.+):([1-9]\d*):([0-9a-f]{12})\z/
20
+ PRO_QUEUE = /\A[^|]+(?:\|[^|]+)*\z/
21
+
15
22
  module_function
16
23
 
17
- # `queue:<public>|<host>|<pid>|<nonce>|<idx>` → [public_q, host, pid,
18
- # nonce], parsed from the right so a `|` inside the queue name is
19
- # tolerated. nil when the key isn't a well-formed private list.
24
+ # [public_q, host, pid, nonce], or nil when the key isn't a well-formed
25
+ # private list.
26
+ #
27
+ # A key that reads as both Pro's and Wurk's is refused: the two name
28
+ # different owners, and judging the wrong one dead would drain a live
29
+ # owner's list. It stays put and the Reaper reports it.
30
+ def parse_full(key)
31
+ return unless key.valid_encoding?
32
+
33
+ pro = parse_pro(key)
34
+ wurk = parse_wurk(key)
35
+ pro && wurk ? nil : pro || wurk
36
+ end
37
+
38
+ # `queue:sq|<identity>|<public>`. Everything after the identity is the
39
+ # queue, so a `|` inside its name is kept.
40
+ def parse_pro(key)
41
+ return unless key.start_with?(PRO_PREFIX)
42
+
43
+ identity, queue = key.delete_prefix(PRO_PREFIX).split('|', 2)
44
+ owner = PRO_IDENTITY.match(identity.to_s)
45
+ return unless owner && queue&.match?(PRO_QUEUE)
46
+
47
+ ["#{Keys::QUEUE_PREFIX}#{queue}", owner[1], owner[2].to_i, owner[3]]
48
+ end
49
+
50
+ # `queue:<public>|<host>|<pid>|<nonce>|<idx>`, parsed from the right so a
51
+ # `|` inside the queue name is tolerated.
20
52
  #
21
53
  # With no known prefix to split on, both owner shapes are tried in
22
54
  # preference order and the first one leaving a real public queue behind
@@ -27,7 +59,7 @@ module Wurk
27
59
  # pipe and puts the real pid in the nonce slot (pipe-bearing queue).
28
60
  # Both misreads are refused: the leftover must be a real queue name and
29
61
  # the pseudo-nonce must be nonce-shaped (see wide_tail).
30
- def parse_full(key)
62
+ def parse_wurk(key)
31
63
  parts = key.split('|')
32
64
  owner_tails(parts).each do |host, pid, nonce, width|
33
65
  public_q = parts[0...-width].join('|')
@@ -229,9 +229,9 @@ module Wurk
229
229
  end
230
230
 
231
231
  # Yields private_list_key, [public_q, host, pid, nonce] for every list.
232
- # MATCH `queue:*|*` matches only private lists (public queue
233
- # keys carry no `|`); PrivateListKey.parse_full drops anything that isn't a
234
- # well-formed `queue:<public>|<host>|<pid>|<nonce>|<idx>`.
232
+ # MATCH `queue:*|*` also matches a public queue with `|` in its name
233
+ # (#public_queue?); PrivateListKey.parse_full drops anything that is not
234
+ # a well-formed Wurk or Sidekiq Pro private list.
235
235
  def each_private_list
236
236
  cursor = '0'
237
237
  loop do
@@ -275,11 +275,19 @@ module Wurk
275
275
  @grace.forget(key)
276
276
  return false
277
277
  end
278
- return false if @grace.recent?(key, owner)
278
+ return false if public_queue?(key) || @grace.recent?(key, owner)
279
279
 
280
280
  owner_gone?(host, pid, nonce)
281
281
  end
282
282
 
283
+ # A public queue's own name can read as a private list. It has no owner to
284
+ # be dead, and draining it would move its waiting jobs to another queue.
285
+ def public_queue?(key)
286
+ redis(idempotent: true) do |c|
287
+ c.call('SISMEMBER', Keys::QUEUES_SET, key.delete_prefix(Keys::QUEUE_PREFIX))
288
+ end == 1
289
+ end
290
+
283
291
  def owner_key(host, pid, nonce)
284
292
  nonce ? "#{host}:#{pid}:#{nonce}" : "#{host}:#{pid}"
285
293
  end
@@ -7,12 +7,10 @@ module Wurk
7
7
  # The Reaper's report on a `queue:*|*` key that is not a private list it
8
8
  # can read the owner of — a list whose owner tail does not parse, say
9
9
  # `queue:<queue>|<host>|not-a-pid|<index>`, left behind by a producer that
10
- # is not Wurk. Sidekiq Pro's four-part shape
11
- # (`queue:<queue>|<host>|<pid>|<index>`) parses as the pre-nonce tail and
12
- # is reclaimed, so Pro's lists are not reported. Nothing will ever reclaim
13
- # the jobs of an unparseable list, so it is said once per key per process
14
- # (WARN, with the list's length) rather than skipped in silence on every
15
- # sweep.
10
+ # is not Wurk, or a key that reads as both a Wurk and a Sidekiq Pro list
11
+ # (PrivateListKey.parse_full). Nothing will ever reclaim the jobs of an
12
+ # unparseable list, so it is said once per key per process (WARN, with the
13
+ # list's length) rather than skipped in silence on every sweep.
16
14
  #
17
15
  # The dedup memory is an in-memory ::Set in THIS process only: one
18
16
  # UnparseableKeys per Reaper, one Reaper per Launcher, one Launcher per
@@ -43,9 +41,10 @@ module Wurk
43
41
  @reported.clear if @reported.size >= MEMORY
44
42
  @reported << key
45
43
  @config.logger.warn do
46
- "reaper: #{key.inspect} looks like a reliable-fetch private list but matches neither " \
47
- 'queue:<queue>|<host>|<pid>|<nonce>|<index> nor the pre-nonce ' \
48
- "queue:<queue>|<host>|<pid>|<index>; its #{size} job(s) will not be recovered " \
44
+ "reaper: #{key.inspect} looks like a reliable-fetch private list but does not read as " \
45
+ 'exactly one of queue:<queue>|<host>|<pid>|<nonce>|<index>, the pre-nonce ' \
46
+ 'queue:<queue>|<host>|<pid>|<index> or Sidekiq Pro\'s queue:sq|<identity>|<queue>; ' \
47
+ "its #{size} job(s) will not be recovered " \
49
48
  'automatically. Inspect it and LMOVE them back onto their queue by hand ' \
50
49
  'if they belong to a dead process. ' \
51
50
  'Reported once per process: every worker that sees the key logs it for itself, ' \
@@ -0,0 +1,156 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Wurk
4
+ # What a job still owes Redis after its `perform` returned and the bookkeeping
5
+ # behind it failed: a sidekiq-unique-jobs lock and a batch's success ack.
6
+ #
7
+ # The job is finished and is never run again for this, since a second run of a
8
+ # bank login or an email is the harm. So the owed writes wait here, in this
9
+ # process, and every Processor retries them before its next fetch. That costs
10
+ # no thread and no sleep during the outage, and they land as soon as Redis
11
+ # answers. A process that exits first says which locks it left (#give_up): the
12
+ # gem's reaper or the lock's TTL clears them.
13
+ class FinishedJobCleanup
14
+ # Names the job, with the Redis error as its `cause`.
15
+ class BookkeepingFailed < ::StandardError; end
16
+
17
+ STORE_ERRORS = [RedisClient::Error, ConnectionPool::Error, ConnectionPool::TimeoutError].freeze
18
+ # Past this many owed jobs the oldest is reported and dropped.
19
+ MEMORY = 10_000
20
+ RETRY_EVERY = 1.0
21
+ RUN_SUFFIX = ':RUN'
22
+ # This lock type is meant to outlive the job, until its TTL.
23
+ KEEPS_LOCK = 'until_expired'
24
+
25
+ Entry = Struct.new(:job, :pool, :config)
26
+
27
+ @entries = []
28
+ @lock = ::Mutex.new
29
+ @draining = ::Mutex.new
30
+ @next_try = 0.0
31
+
32
+ class << self
33
+ def store_error?(error) = STORE_ERRORS.any? { |klass| error.is_a?(klass) }
34
+
35
+ # Reports the failure, tries the owed writes once, keeps what did not land.
36
+ def settle(job, error, pool:, config:)
37
+ report(job, error, config)
38
+ entry = Entry.new(job, pool, config)
39
+ return unless owes_anything?(job)
40
+ return if attempt?(entry)
41
+
42
+ remember(entry)
43
+ config.logger.error { "#{describe(job)}: waiting for Redis to finish its cleanup" }
44
+ end
45
+
46
+ # Hot path: one empty check per fetch while nothing is owed.
47
+ def drain
48
+ return if @entries.empty? || monotonic < @next_try
49
+ return unless @draining.try_lock
50
+
51
+ begin
52
+ drain_entries
53
+ ensure
54
+ @draining.unlock
55
+ end
56
+ end
57
+
58
+ # The process is stopping: one last try, then say what is left.
59
+ def give_up
60
+ return if @entries.empty?
61
+
62
+ @next_try = 0.0
63
+ drain
64
+ @lock.synchronize { @entries.slice!(0..) }.each { |entry| warn_left(entry) }
65
+ end
66
+
67
+ def pending = @lock.synchronize { @entries.size }
68
+
69
+ def reset!
70
+ @lock.synchronize { @entries.clear }
71
+ @next_try = 0.0
72
+ end
73
+
74
+ private
75
+
76
+ def drain_entries
77
+ while (entry = @lock.synchronize { @entries.first })
78
+ unless attempt?(entry)
79
+ @next_try = monotonic + RETRY_EVERY
80
+ return
81
+ end
82
+ @lock.synchronize { @entries.delete_at(@entries.index { |held| held.equal?(entry) } || @entries.size) }
83
+ entry.config.logger.info { "#{describe(entry.job)}: cleanup finished after the Redis failure" }
84
+ end
85
+ end
86
+
87
+ # true when nothing more can be done for this entry. Idempotent, so an
88
+ # entry half done by an earlier try is safe to run again.
89
+ def attempt?(entry)
90
+ release_unique_locks(entry.job)
91
+ ack_batch(entry.job, entry.pool)
92
+ true
93
+ rescue StandardError => e
94
+ return false if store_error?(e)
95
+
96
+ entry.config.handle_exception(e, { context: "#{describe(entry.job)}: cleanup failed", job: entry.job })
97
+ true
98
+ end
99
+
100
+ # Locksmith#unlock only drops a lock this jid holds. Both digests: an
101
+ # until_and_while_executing job takes its base lock back when an error
102
+ # crosses it, on top of the `:RUN` lock it may still hold.
103
+ def release_unique_locks(job)
104
+ locksmith = UniqueJobsCompat.locksmith_class
105
+ digests(job).each { |digest| locksmith.new(job.merge('lock_digest' => digest)).unlock }
106
+ end
107
+
108
+ def digests(job)
109
+ digest = job['lock_digest']
110
+ return [] unless digest && job['lock'].to_s != KEEPS_LOCK && UniqueJobsCompat.locksmith_class
111
+
112
+ base = digest.delete_suffix(RUN_SUFFIX)
113
+ [base, "#{base}#{RUN_SUFFIX}"]
114
+ end
115
+
116
+ # A replayed ack removes nothing, and the callback markers absorb a second
117
+ # fire (Batch::ServerMiddleware#ack_success).
118
+ def ack_batch(job, pool)
119
+ bid = job['bid']
120
+ return unless bid
121
+
122
+ _removed, pending, live, kids = pool.with { |conn| Batch.ack_success(conn, bid, job['jid']) }
123
+ Batch::Callbacks.maybe_fire(bid, pending: pending, live: live, kids: kids)
124
+ end
125
+
126
+ def owes_anything?(job) = job['bid'] || digests(job).any?
127
+
128
+ def remember(entry)
129
+ dropped = @lock.synchronize do
130
+ @entries << entry
131
+ @entries.shift if @entries.size > MEMORY
132
+ end
133
+ warn_left(dropped) if dropped
134
+ end
135
+
136
+ def warn_left(entry)
137
+ entry.config.logger.error do
138
+ "#{describe(entry.job)}: cleanup never reached Redis. Locks left: #{digests(entry.job).join(', ')}; " \
139
+ 'the sidekiq-unique-jobs reaper or the lock TTL clears them. Batch: ' \
140
+ "#{entry.job['bid'] || 'none'}"
141
+ end
142
+ end
143
+
144
+ def report(job, error, config)
145
+ raise BookkeepingFailed, "#{describe(job)}: Redis failed after perform returned, not running it again " \
146
+ "(#{error.class}: #{error.message}). Locks: #{digests(job).join(', ')}", cause: error
147
+ rescue BookkeepingFailed => e
148
+ config.handle_exception(e, { context: 'Bookkeeping failed after perform', job: job })
149
+ end
150
+
151
+ def describe(job) = "#{job['class']} JID-#{job['jid']}"
152
+
153
+ def monotonic = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC)
154
+ end
155
+ end
156
+ end
@@ -38,14 +38,6 @@ module Wurk
38
38
  # short-circuits processing (e.g. interrupt-handler re-pushed the job).
39
39
  class Skip < Handled; end
40
40
 
41
- # Raised by Processor when Redis stopped answering after `perform` had
42
- # returned: the job did its work and only the bookkeeping behind it (a
43
- # batch ack, a status row) failed. Counted as a failure it would be retried
44
- # with a stale count or, on a last attempt, killed, and a batch would mark
45
- # itself dead over a job that succeeded. Both guards let it through to the
46
- # Processor, which puts the job back to run again. `cause` is the Redis error.
47
- class StoreUnavailableAfterPerform < ::StandardError; end
48
-
49
41
  def initialize(capsule)
50
42
  @capsule = capsule
51
43
  @config = capsule
@@ -58,7 +50,7 @@ module Wurk
58
50
  # bubbles up so the swarm can drain.
59
51
  def global(jobstr, queue)
60
52
  yield
61
- rescue Handled, Wurk::Shutdown, StoreUnavailableAfterPerform
53
+ rescue Handled, Wurk::Shutdown
62
54
  raise
63
55
  rescue Exception => e # rubocop:disable Lint/RescueException
64
56
  raise Wurk::Shutdown if exception_caused_by_shutdown?(e)
@@ -79,7 +71,7 @@ module Wurk
79
71
  # circuit `global`'s rescue.
80
72
  def local(jobinst, jobstr, queue)
81
73
  yield
82
- rescue Handled, Wurk::Shutdown, StoreUnavailableAfterPerform
74
+ rescue Handled, Wurk::Shutdown
83
75
  raise
84
76
  rescue Exception => e # rubocop:disable Lint/RescueException
85
77
  raise Wurk::Shutdown if exception_caused_by_shutdown?(e)
data/lib/wurk/launcher.rb CHANGED
@@ -62,7 +62,7 @@ module Wurk
62
62
  KILL_JOIN = 0.25
63
63
 
64
64
  attr_accessor :managers, :poller, :periodic_poller, :metrics_rollup, :queue_rollup, :metrics_flusher, :history,
65
- :queue_consumers
65
+ :queue_consumers, :sidekiq_cron_poller
66
66
 
67
67
  def initialize(config, embedded: false)
68
68
  @config = config
@@ -361,7 +361,7 @@ module Wurk
361
361
  # history snapshotter is opt-in and an embedded boot may have stripped the
362
362
  # rest.
363
363
  def start_periodic_components
364
- [@poller, @leader, @periodic_poller, @metrics_rollup,
364
+ [@poller, @leader, @periodic_poller, @sidekiq_cron_poller, @metrics_rollup,
365
365
  @queue_rollup, @queue_consumers, @metrics_flusher, @history].compact.each(&:start)
366
366
  end
367
367
 
@@ -369,8 +369,8 @@ module Wurk
369
369
  # for it (the flusher also writes its last window): side by side, every loop
370
370
  # hears the stop whatever another is stuck on. Returns the threads.
371
371
  def stop_periodic_components
372
- stops = [@metrics_flusher, @periodic_poller, @metrics_rollup, @queue_rollup, @queue_consumers,
373
- @history].compact.map { |t| [t.class, -> { t.terminate }] }
372
+ stops = [@metrics_flusher, @periodic_poller, @sidekiq_cron_poller, @metrics_rollup, @queue_rollup,
373
+ @queue_consumers, @history].compact.map { |t| [t.class, -> { t.terminate }] }
374
374
  stops << ['reaper', -> { @reaper.stop }] if @reaper
375
375
  stops.map do |label, stop|
376
376
  Thread.new { teardown_step(label, &stop) }.tap { |thread| thread.report_on_exception = false }
@@ -545,6 +545,8 @@ module Wurk
545
545
  #
546
546
  # poller / reaper every process, work shared through Redis
547
547
  # periodic_poller leader only enqueues — that is the exactly-once guard
548
+ # sidekiq_cron_poller native sidekiq-cron (Wurk::SidekiqCron), only when
549
+ # loaded and the gem is not; leader only, like the above
548
550
  # metrics_rollup leader only writes the cluster-total chart buckets
549
551
  # (cadence: `config.metrics_rollup_interval`)
550
552
  # queue_rollup leader only writes the `qm|…` per-queue gauges
@@ -558,6 +560,7 @@ module Wurk
558
560
  # Not @cron_poller: sidekiq-cron's Launcher prepend assigns that ivar and
559
561
  # owns its lifecycle. Both pollers run, each over its own registrations.
560
562
  @periodic_poller = Wurk::Cron::Poller.new(@config)
563
+ @sidekiq_cron_poller = Wurk::SidekiqCron::Poller.new(@config) if sidekiq_cron_polls?
561
564
  @metrics_rollup = Wurk::Metrics::Rollup.new(@config)
562
565
  @queue_rollup = Wurk::Metrics::QueueRollup.new(@config)
563
566
  @queue_consumers = Wurk::QueueConsumers::Watch.new(@config)
@@ -565,6 +568,14 @@ module Wurk
565
568
  @history = Wurk::History.new(@config) if @config.history_enabled?
566
569
  end
567
570
 
571
+ # The app loaded `Sidekiq::Cron` and it is wurk's: the gem, when bundled,
572
+ # prepends its own poller onto this class. A poll interval of 0 turns it
573
+ # off, as in the gem.
574
+ def sidekiq_cron_polls?
575
+ defined?(Wurk::SidekiqCron) && Wurk::SidekiqCron.active? &&
576
+ Wurk::SidekiqCron.configuration.cron_poll_interval.to_i.positive?
577
+ end
578
+
568
579
  # Filled in by #run. Declared up front so #initialize reads as the full
569
580
  # inventory of what a Launcher owns.
570
581
  def reset_thread_state
@@ -0,0 +1,5 @@
1
+ -- sidekiq-unique-jobs 8.x delete.lua: drop one digest's queue-time keys and its
2
+ -- `uniquejobs:digests` entry. Every key is in KEYS.
3
+ -- KEYS = [digest, queued, primed, locked, info, changelog, digests, expiring_digests]
4
+ local count = redis.call("ZREM", KEYS[7], KEYS[1])
5
+ return count + redis.call("UNLINK", KEYS[1], KEYS[2], KEYS[3], KEYS[4], KEYS[5])
@@ -0,0 +1,6 @@
1
+ -- sidekiq-unique-jobs 8.x delete_by_digest.lua: the queue-time and run-time keys
2
+ -- of one digest, and its entry in the index the caller names. Every key is in KEYS.
3
+ -- KEYS = [digest, queued, primed, locked, run_digest, run_queued, run_primed, run_locked, index]
4
+ local count = redis.call("UNLINK", KEYS[1], KEYS[2], KEYS[3], KEYS[4], KEYS[5], KEYS[6], KEYS[7], KEYS[8])
5
+ redis.call("ZREM", KEYS[9], KEYS[1])
6
+ return count
@@ -0,0 +1,42 @@
1
+ -- sidekiq-unique-jobs 8.x delete_job_by_digest.lua (on_conflict: :replace): remove
2
+ -- the first job carrying the digest from its queue, else the schedule, else the
3
+ -- retry set, and return its payload. The gem's copy reads `uniquejobs:digests`
4
+ -- without declaring it, which Dragonfly and a strict Redis refuse; here it is KEYS[4].
5
+ -- KEYS = [queue:<name>, schedule, retry, uniquejobs:digests]
6
+ -- ARGV = [digest]
7
+ local digest = ARGV[1]
8
+ local per = 50
9
+
10
+ local total = redis.call("LLEN", KEYS[1])
11
+ for index = 0, total, per do
12
+ local items = redis.call("LRANGE", KEYS[1], index, index + per - 1)
13
+ if #items == 0 then break end
14
+ for _, item in ipairs(items) do
15
+ if string.find(item, digest, 1, true) then
16
+ redis.call("LREM", KEYS[1], 1, item)
17
+ return item
18
+ end
19
+ end
20
+ end
21
+
22
+ local score = redis.call("ZSCORE", KEYS[4], digest)
23
+ for set = 2, 3 do
24
+ local name = KEYS[set]
25
+ local size = redis.call("ZCARD", name)
26
+ for offset = 0, size, per do
27
+ local items
28
+ if score then
29
+ items = redis.call("ZRANGE", name, score, "+inf", "BYSCORE", "LIMIT", offset, per)
30
+ else
31
+ items = redis.call("ZRANGE", name, offset, offset + per - 1)
32
+ end
33
+ if #items == 0 then break end
34
+ for _, item in ipairs(items) do
35
+ if string.find(item, digest, 1, true) then
36
+ redis.call("ZREM", name, item)
37
+ return item
38
+ end
39
+ end
40
+ end
41
+ end
42
+ return nil